all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Functions for inserting name of code blocks
@ 2021-08-21  1:31 Rodrigo Morales
  0 siblings, 0 replies; only message in thread
From: Rodrigo Morales @ 2021-08-21  1:31 UTC (permalink / raw)
  To: emacs-orgmode


This thread asks for feedback on functions that I've created. These 2
functions have to do with inserting, at point, the name of a code block
which exists in the current buffer or in the library of babel. You can
find the functions below.

#+begin_src elisp
(defun my/org-babel-insert-name-src-block-current-buffer ()
  "Prompts for the name of a code block in the current buffer and
insert it at point."
  (interactive)
  (let* ((names (org-babel-src-block-names))
         (selected-name (completing-read "Names: " names nil t)))
    (insert selected-name)))
#+end_src

#+begin_src elisp
(define-key org-mode-map (kbd "C-c M-n b") 'my/org-babel-insert-name-src-block-current-buffer)
#+end_src

#+begin_src elisp
(defun my/org-babel-insert-name-src-block-lob ()
  "Prompts for the name of a code block in
`org-babel-library-of-babel' and insert it at point."
  (interactive)
  (unless org-babel-library-of-babel
    (error "The variable \"org-babel-library-of-babel\" is empty."))
  (let* ((names (mapcar 'car org-babel-library-of-babel))
         (selected-name (completing-read "Names: " names nil t)))
    (insert selected-name)))
#+end_src

#+begin_src elisp
(define-key org-mode-map (kbd "C-c M-n l") 'my/org-babel-insert-name-src-block-lob)
#+end_src



^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-08-21  1:33 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-08-21  1:31 Functions for inserting name of code blocks Rodrigo Morales

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.