Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Emacs lisp - autocomplete bookmark names

I'm new to elisp. http://www.gnu.org/s/emacs/manual/html_node/elisp/Interactive-Codes.html#Interactive-Codes lists 'code characters' for interactive parameters, which AFAIK modifies the behaviour of the input mechanism when prompting the user for input (eg: if you specify that the input is a filename that exists, emacs' autocomplete functionality will look for file names that exists).

I'm trying to find a code for a bookmark name that already exists - ie: emacs will prompt the user for a bookmark name, and upon pressing tab emacs will show possible bookmark name completions.

Does such a code exist?

like image 341
Trent Avatar asked Nov 05 '22 22:11

Trent


1 Answers

Use completing-read for that. You could write a function that prompts the user for a bookmark like so:

(defun my-function ()
  (interactive)
  (let ((bookmark (completing-read "Bookmark: " (bookmark-all-names))))
    ...))

If you prefer the prompting to be part of interactive (so that the result will be bound automatically to your function's arguments), you could use the following alternative:

(defun my-function (bookmark)
  (interactive (list (completing-read "Bookmark: " (bookmark-all-names))))
  ...)

For Emacs to find the function bookmark-all-names you also have to add the following line to your .emacs file:

(require 'bookmark)
like image 139
Thomas Avatar answered Nov 09 '22 07:11

Thomas