emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Rodrigo Morales <moralesrodrigo1100@gmail.com>
To: emacs-orgmode@gnu.org
Subject: Functions for inserting name of code blocks
Date: Fri, 20 Aug 2021 20:31:36 -0500	[thread overview]
Message-ID: <8735r38txj.fsf@gmail.com> (raw)


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	other threads:[~2021-08-21  1:33 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=8735r38txj.fsf@gmail.com \
    --to=moralesrodrigo1100@gmail.com \
    --cc=emacs-orgmode@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).