* company-mode completions for noweb references
@ 2018-11-06 18:32 Nik Clayton
2018-11-07 6:33 ` Eric S Fraga
0 siblings, 1 reply; 2+ messages in thread
From: Nik Clayton @ 2018-11-06 18:32 UTC (permalink / raw)
To: emacs-orgmode
[-- Attachment #1: Type: text/plain, Size: 1942 bytes --]
Hoi,
I've been writing a few things using Org where I'm making frequent use of
noweb references in SRC blocks, and decided that completion would be handy
for them.
This function will complete "^<<" with a list of the defined named blocks
in the current file, if you're in a SRC block.
It could be made smarter (e.g., only offer the completion if ":noweb yes"
is set, only offer to complete from named blocks with the same language as
the current block), but I thought I'd throw it out here in case anyone else
finds it useful.
Best, N
(defun my/org-src-block-name-backend (command &optional arg &rest ignored)
"Complete `<<' with the names of defined SRC blocks."
(interactive (list 'interactive))
(cl-case command
(interactive (company-begin-backend 'my/org-src-block-name-backend))
(init (require 'org-element))
(prefix (and (eq major-mode 'org-mode)
(eq 'src-block (car (org-element-at-point)))
(cons (company-grab-line "^<<\\(\\w*\\)" 1) t)))
(candidates
(org-element-map (org-element-parse-buffer) 'src-block
(lambda (src-block)
(let ((name (org-element-property :name src-block)))
(when name
(propertize
name
:value (org-element-property :value src-block)
:annotation (org-element-property :raw-value (org-element-lineage
src-block '(headline)))))))))
(sorted t) ; Show candidates in same order as doc
(ignore-case t)
(duplicates nil) ; No need to remove duplicates
(post-completion ; Close the reference with ">>"
(insert ">>"))
;; Show the contents of the block in a doc-buffer. If you have
;; company-quickhelp-mode enabled it will show in a popup
(doc-buffer (company-doc-buffer (get-text-property 0 :value arg)))
(annotation (format " [%s]" (get-text-property 0 :annotation arg)))))
(add-to-list 'company-backends 'my/org-src-block-name-backend)
[-- Attachment #2: Type: text/html, Size: 2519 bytes --]
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: company-mode completions for noweb references
2018-11-06 18:32 company-mode completions for noweb references Nik Clayton
@ 2018-11-07 6:33 ` Eric S Fraga
0 siblings, 0 replies; 2+ messages in thread
From: Eric S Fraga @ 2018-11-07 6:33 UTC (permalink / raw)
To: Nik Clayton; +Cc: emacs-orgmode
On Tuesday, 6 Nov 2018 at 19:32, Nik Clayton wrote:
> Hoi,
>
> I've been writing a few things using Org where I'm making frequent use of
> noweb references in SRC blocks, and decided that completion would be handy
> for them.
Thanks for this. Very useful. I'll incorporate it into my config and
will come back if I see anything strange.
--
Eric S Fraga via Emacs 27.0.50, Org release_9.1.13-783-g97fac4
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2018-11-07 6:43 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-11-06 18:32 company-mode completions for noweb references Nik Clayton
2018-11-07 6:33 ` Eric S Fraga
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).