Add hydra head to prompt for source language

This commit is contained in:
contrapunctus 2022-01-17 12:22:51 +05:30
parent 0cbfa4c24c
commit 02315b1b8b
1 changed files with 7 additions and 5 deletions

View File

@ -804,7 +804,8 @@ _u_: next word ^_l_: edit lines^ _s_: next whole symbol
#+BEGIN_SRC emacs-lisp
(defhydra my-org-hydra-block (:color blue)
"Org block"
("l" (my-org-insert-block "SRC" nil) "Source")
("l" (my-org-insert-block "SRC" nil) "Source (current language)")
("L" (my-org-insert-block "SRC" nil nil t) "Source (prompt)")
("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")
@ -3842,7 +3843,7 @@ 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-insert-block (type &optional lang header-args)
(defun my-org-insert-block (type &optional lang header-args ask)
"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.
@ -3850,13 +3851,14 @@ If TYPE is SRC, LANG should be the name of the language as a string, e.g. \"emac
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."
or with ASK, 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))
(stringp my-org-src-default-lang)
(not ask))
my-org-src-default-lang)
(src-block-p
((and src-block-p ask)
(completing-read "Source block language: "
(mapcar #'cl-first org-src-lang-modes)))
(t nil)))