emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Functions for inserting name of code blocks


From: Rodrigo Morales
Subject: Functions for inserting name of code blocks
Date: Fri, 20 Aug 2021 20:31:36 -0500

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




reply via email to

[Prev in Thread] Current Thread [Next in Thread]