Split Org config into multiple blocks; remove unused code; update prefixes

This commit is contained in:
contrapunctus 2022-01-25 14:12:19 +05:30
parent 5b1c670b1b
commit 05ea748538
1 changed files with 45 additions and 69 deletions

114
init.org
View File

@ -783,7 +783,7 @@ _u_: next word ^_l_: edit lines^ _s_: next whole symbol
("L" my-literate-elisp-hydra/body "literate-elisp") ("L" my-literate-elisp-hydra/body "literate-elisp")
("p" org-set-property "property") ("p" org-set-property "property")
("l" my-org-hydra-block/body "source block") ("l" my-org-hydra-block/body "source block")
("t" my-org-hydra-set-tags "tags") ("t" my-org-set-tags "tags")
("C-t" org-todo "todo" :color red) ("C-t" org-todo "todo" :color red)
("v" my-org-hydra-nav/body "navigation") ("v" my-org-hydra-nav/body "navigation")
("b" (my-compile-org-lp) "compile") ("b" (my-compile-org-lp) "compile")
@ -3822,7 +3822,6 @@ SLIME opens CLHS links in Firefox, but I'd rather open them in Tor Browser; Tor
;; "C-m" 'org-return-indent ;; "C-m" 'org-return-indent
"C-c C-9" 'org-mark-ring-goto "C-c C-9" 'org-mark-ring-goto
"C-c C-/" 'org-sparse-tree "C-c C-/" 'org-sparse-tree
"M-w" 'cp-copy-line-or-link
"C-M-x" 'cp/eval-sexp "C-M-x" 'cp/eval-sexp
"C-c C-o" 'my-org-open "C-c C-o" 'my-org-open
;; boon ;; boon
@ -3865,30 +3864,40 @@ SLIME opens CLHS links in Firefox, but I'd rather open them in Tor Browser; Tor
(org-link-set-parameters "gemini" :export #'my-export-gemini-link) (org-link-set-parameters "gemini" :export #'my-export-gemini-link)
(org-link-set-parameters "xmpp" :export #'my-export-xmpp-link)) (org-link-set-parameters "xmpp" :export #'my-export-xmpp-link))
;; https://lists.gnu.org/archive/html/emacs-orgmode/2018-02/msg00082.html (defun contrapunctus-disable-nameless-key ()
(defun my-export-link-helper (link desc format) (define-key nameless-mode-map (kbd "C-c C--") nil))
(cond #+END_SRC
((eq format 'html)
(format "<a href=\"%s\">%s</a>" link desc))
((eq format 'latex)
;; (format "\\href{%s}{%s}" link desc)
(format "\\url{%s}" link))
(t ;; `ascii', `md', `hugo', etc.
(format "[%s](%s)" desc link))))
*** gemini: and xmpp: links
https://lists.gnu.org/archive/html/emacs-orgmode/2018-02/msg00082.html
#+BEGIN_SRC emacs-lisp
(defun my-export-link-helper (link desc format)
(cond
((eq format 'html)
(format "<a href=\"%s\">%s</a>" link desc))
((eq format 'latex)
;; (format "\\href{%s}{%s}" link desc)
(format "\\url{%s}" link))
(t ;; `ascii', `md', `hugo', etc.
(format "[%s](%s)" desc link))))
#+END_SRC
#+BEGIN_SRC emacs-lisp
(defun my-export-gemini-link (link desc format) (defun my-export-gemini-link (link desc format)
"Create export version of LINK and DESC to FORMAT." "Create export version of LINK and DESC to FORMAT."
(let ((link (concat "gemini:" link))) (let ((link (concat "gemini:" link)))
(my-export-link-helper link desc format))) (my-export-link-helper link desc format)))
#+END_SRC
#+BEGIN_SRC emacs-lisp
(defun my-export-xmpp-link (link desc format) (defun my-export-xmpp-link (link desc format)
"Create export version of LINK and DESC to FORMAT." "Create export version of LINK and DESC to FORMAT."
(let ((link (concat "xmpp:" link))) (let ((link (concat "xmpp:" link)))
(my-export-link-helper link desc format))) (my-export-link-helper link desc format)))
#+END_SRC
(defun contrapunctus-disable-nameless-key () *** my-org-insert-block
(define-key nameless-mode-map (kbd "C-c C--") nil)) #+BEGIN_SRC emacs-lisp
(defun my-org-insert-block (type &optional lang header-args ask) (defun my-org-insert-block (type &optional lang header-args ask)
"Insert block of TYPE at point, or at beginning and end of region. "Insert block of TYPE at point, or at beginning and end of region.
TYPE should be an Org block type, e.g. SRC, QUOTE, etc. TYPE should be an Org block type, e.g. SRC, QUOTE, etc.
@ -3934,7 +3943,9 @@ or with ASK, prompt the user for a language."
(insert "\n" end-string) (insert "\n" end-string)
(goto-char point-inside-block) (goto-char point-inside-block)
(insert indent)))))) (insert indent))))))
#+END_SRC
#+BEGIN_SRC emacs-lisp
;; (use-package org-src-mode ;; (use-package org-src-mode
;; :hook (org-src-mode . (lambda () (when (derived-mode-p 'emacs-lisp-mode))))) ;; :hook (org-src-mode . (lambda () (when (derived-mode-p 'emacs-lisp-mode)))))
@ -3945,7 +3956,10 @@ or with ASK, prompt the user for a language."
;; ;; todo - check if we are on a heading ;; ;; todo - check if we are on a heading
;; (org-forward-heading-same-level) ;; (org-forward-heading-same-level)
;; ()) ;; ())
#+END_SRC
*** my-org-open
#+BEGIN_SRC emacs-lisp
;; I dislike having to navigate within a line to reach a link - with ;; I dislike having to navigate within a line to reach a link - with
;; this command I just need to be on the same line as the link. ;; this command I just need to be on the same line as the link.
(defun my-org-open (&optional arg reference-buffer) (defun my-org-open (&optional arg reference-buffer)
@ -3954,57 +3968,10 @@ or with ASK, prompt the user for a language."
(unless (looking-at-p (rx-to-string '(or "http" "["))) (unless (looking-at-p (rx-to-string '(or "http" "[")))
(org-next-link)) (org-next-link))
(org-open-at-point)) (org-open-at-point))
#+END_SRC
(defun cp-copy-line-or-link (prefix-arg) *** org-table-convert-tsv
"Copy address of org-mode link after point, ignoring whitespace, #+BEGIN_SRC emacs-lisp
link description (if any) and org-mode header and list syntax. If
not before a link, or with a prefix arg, call
`whole-line-or-region-kill-ring-save' instead.
BUG - improper behaviour with checkboxes.
2018-03-17T21:15:17+0530 - hopefully fixed now."
(interactive "P")
(let ((point-a (point)))
(cl-flet ((copy-to-closing-bracket
()
(let ((point-b (point)))
(re-search-forward "\\]")
(copy-region-as-kill point-b
(- (point) 1)))))
(if (save-excursion
(or (use-region-p)
prefix-arg
(cp/re-search-line "\\[[-X ]\\]")))
(whole-line-or-region-kill-ring-save prefix-arg)
(cond ( ;; (cp/org-link-ahead-p)
(cp/re-search-line "\\[")
;; (if (looking-at "\\[")
;; (forward-char))
(forward-char)
(copy-to-closing-bracket)
(goto-char point-a))
( ;; (cp/org-link-ahead-p 'implicit)
(cp/re-search-line "http")
(backward-word)
(let ((point-b (point)))
(re-search-forward (rx (or eol (and printing " "))))
(copy-region-as-kill point-b
(point)))
(goto-char point-a))
;; TODO - org-previous-link will land you at the start
;; of the DESCRIPTION of the previous link, if it has
;; one, but to the user it will look like they are at
;; the start of the link. Add a case to handle this.
;; Does not work if there is an org TODO marker in a
;; header.
(t (whole-line-or-region-kill-ring-save prefix-arg)))))))
(defun cp/org-table-convert-tsv () (defun cp/org-table-convert-tsv ()
(interactive) (interactive)
(with-output-to-temp-buffer "cp/org-table-convert-tsv" (with-output-to-temp-buffer "cp/org-table-convert-tsv"
@ -4015,8 +3982,11 @@ BUG - improper behaviour with checkboxes.
(with-current-buffer "cp/org-table-convert-tsv" (with-current-buffer "cp/org-table-convert-tsv"
(remove-hook 'before-save-hook 'delete-trailing-whitespace) (remove-hook 'before-save-hook 'delete-trailing-whitespace)
(write-file (read-from-minibuffer "Output filename: ")))) (write-file (read-from-minibuffer "Output filename: "))))
#+END_SRC
(defun my-org-hydra-set-tags () *** my-org-set-tags - using completing-read-multiple for setting tags
#+BEGIN_SRC emacs-lisp
(defun my-org-set-tags ()
(interactive) (interactive)
(let ((all-tags (org-get-buffer-tags)) (let ((all-tags (org-get-buffer-tags))
(current-tags (org-get-tags))) (current-tags (org-get-tags)))
@ -4027,7 +3997,10 @@ BUG - improper behaviour with checkboxes.
"Tag: " all-tags nil 'confirm "Tag: " all-tags nil 'confirm
(mapconcat #'identity current-tags ",") (mapconcat #'identity current-tags ",")
'org-tags-history))))) 'org-tags-history)))))
#+END_SRC
***
#+BEGIN_SRC emacs-lisp
(defun cp/marked-files->markup-links-org (filenames) (defun cp/marked-files->markup-links-org (filenames)
(mapcar (lambda (filename) (mapcar (lambda (filename)
(let ((link-pre "[[file:") (let ((link-pre "[[file:")
@ -4036,18 +4009,21 @@ BUG - improper behaviour with checkboxes.
filenames)) filenames))
#+END_SRC #+END_SRC
*** my-org-insert-timestamp
#+BEGIN_SRC emacs-lisp #+BEGIN_SRC emacs-lisp
(defun contrapunctus-org-insert-timestamp () (defun my-org-insert-timestamp ()
(save-excursion (save-excursion
(org-set-property "CREATED" (format-time-string "%FT%T%z")))) (org-set-property "CREATED" (format-time-string "%FT%T%z"))))
(use-package org-indent (use-package org-indent
:hook (org-mode . org-indent-mode)) :hook (org-mode . org-indent-mode))
(use-package ox-texinfo (with-eval-after-load 'ox
:hook (org-mode . (require 'ox-texinfo))) ;; ideally, I'd run this in :before advice for org-export... (require 'ox-texinfo)) ;; ideally, I'd load this in :before advice for org-export...
#+END_SRC #+END_SRC
*** load org-babel languages on demand
From https://emacs.stackexchange.com/questions/20577/org-babel-load-all-languages-on-demand From https://emacs.stackexchange.com/questions/20577/org-babel-load-all-languages-on-demand
#+BEGIN_SRC emacs-lisp #+BEGIN_SRC emacs-lisp
(defadvice org-babel-execute-src-block (around load-language nil activate) (defadvice org-babel-execute-src-block (around load-language nil activate)
"Load language if needed" "Load language if needed"