Remove language-specific source block hydra heads

This commit is contained in:
contrapunctus 2022-01-17 12:02:17 +05:30
parent 6d85a1d42e
commit 0cbfa4c24c
1 changed files with 27 additions and 14 deletions

View File

@ -803,15 +803,12 @@ _u_: next word ^_l_: edit lines^ _s_: next whole symbol
**** org block
#+BEGIN_SRC emacs-lisp
(defhydra my-org-hydra-block (:color blue)
"Org source block"
("e" (my-org-hydra-insert-block "SRC" "emacs-lisp") "Emacs Lisp")
("t" (my-org-hydra-insert-block "SRC" "emacs-lisp :tangle test :load test") "Emacs Lisp test")
("E" (my-org-hydra-insert-block "SRC" "emacs-lisp :tangle no :load no") "Emacs Lisp example")
("h" (my-org-hydra-insert-block "SRC" "sh") "Shell")
("o" (my-org-hydra-insert-block "QUOTE") "quote")
("v" (my-org-hydra-insert-block "VERSE") "verse")
("s" (my-org-hydra-insert-block "SRC" "scheme") "Scheme")
("l" (my-org-hydra-insert-block "SRC" "lisp") "Common Lisp"))
"Org block"
("l" (my-org-insert-block "SRC" nil) "Source")
("t" (my-org-insert-block "SRC" nil ":tangle test :load test") "Source test")
("e" (my-org-insert-block "SRC" nil ":tangle no :load no") "Source example")
("o" (my-org-insert-block "QUOTE") "quote")
("v" (my-org-insert-block "VERSE") "verse"))
#+END_SRC
**** org navigation
@ -3845,17 +3842,33 @@ SLIME opens CLHS links in Firefox, but I'd rather open them in Tor Browser; Tor
(defun contrapunctus-disable-nameless-key ()
(define-key nameless-mode-map (kbd "C-c C--") nil))
(defun my-org-hydra-insert-block (type &optional lang)
(defun my-org-insert-block (type &optional lang header-args)
"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.
If TYPE is SRC, LANG should be the name of the language as a string, e.g. \"emacs-lisp\"."
(let* ((column (- (point) (point-at-bol)))
If TYPE is SRC, LANG should be the name of the language as a string, e.g. \"emacs-lisp\".
If LANG is not supplied, use the value of
`my-org-src-default-lang'. If `my-org-src-default-lang' is nil,
prompt the user for a language."
(let* ((src-block-p (equal type "SRC"))
(lang (cond ((stringp lang) lang)
((and (bound-and-true-p my-org-src-default-lang)
(stringp my-org-src-default-lang))
my-org-src-default-lang)
(src-block-p
(completing-read "Source block language: "
(mapcar #'cl-first org-src-lang-modes)))
(t nil)))
(column (- (point) (point-at-bol)))
(indent (make-string column ?\s))
(region-start (region-beginning))
(region-end (region-end))
(start-string (format "#+BEGIN_%s %s\n" type
(if (stringp lang) lang "")))
(start-string (format "#+BEGIN_%s %s%s\n" type
(if src-block-p lang "")
(if (and src-block-p header-args)
(format " %s" header-args)
"")))
(end-string (format "%s#+END_%s\n" indent type)))
;; create a block around a region - preserve position of point
(cond ((region-active-p)