From: Eshel Yaron Date: Mon, 25 Dec 2023 19:20:54 +0000 (+0100) Subject: Narrow bookmark completions by bookmark type with 'C-x n m' X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=6f85d9a456bd30f074575a5b08de2eebaa151f5a;p=emacs.git Narrow bookmark completions by bookmark type with 'C-x n m' * lisp/bookmark.el (bookmark-narrow-completions-by-type): New function. (bookmark-completing-read): Use it as a 'narrow-completions-function'. * doc/emacs/regs.texi (Bookmarks): Document it, as well as bookmark types in general. * etc/NEWS: Mention it. --- diff --git a/doc/emacs/regs.texi b/doc/emacs/regs.texi index 20b39b8408f..9ced50a7e51 100644 --- a/doc/emacs/regs.texi +++ b/doc/emacs/regs.texi @@ -428,3 +428,18 @@ points to. Insert in the buffer the @emph{contents} of the file that bookmark @var{bookmark} points to. @end table + +@cindex bookmark types +@cindex types of bookmarks + Bookmarks can also record positions in buffers that are not visiting +any file, such as web pages that you browse with EWW +(@pxref{Top,EWW,,eww,}). While jumping to a regular bookmark simply +visits the corresponding file, different @dfn{bookmark types} can do +different things when you jump to them. As an example, EWW bookmarks +store a URL instead of a file name, and jumping to such an EWW +bookmark opens that URL in EWW. + +When you specify a bookmark name in the minibuffer in response to a +prompt from one of the above commands, you can use @kbd{C-x n m} to +restrict the list of bookmark completion candidates to only include +bookmarks of a given type. diff --git a/etc/NEWS b/etc/NEWS index ac7f8b12abb..afc59520dd4 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -719,8 +719,15 @@ in the minibuffer history, with more recent candidates appearing first. *** New commands for narrowing (restricting) minibuffer completions list. You can now use 'C-x n n' ('minibuffer-narrow-completions-to-current') in the minibuffer to restrict the list of possible completions to only -include candidates matching the current minibuffer input. See the -Info node "(emacs) Narrow Completions" for more information. +include candidates matching the current minibuffer input. New command +'C-x n m' ('minibuffer-narrow-completions') is similar, but uses an +alternative restriction method that depends on the relevant completion +candidates. For example, commands that read an Elisp symbol let you +restrict the completions list with 'C-x n m' to only include symbols +with a given property. Similarly, commands that read a bookmark name +let you restrict the completions list to only include bookmarks of a +given type. See the new Info node "(emacs) Narrow Completions" for +more information. *** New minor mode 'completions-auto-update-mode'. This global minor mode automatically updates the *Completions* buffer diff --git a/lisp/bookmark.el b/lisp/bookmark.el index 71d76cb4291..e0e88024473 100644 --- a/lisp/bookmark.el +++ b/lisp/bookmark.el @@ -561,11 +561,31 @@ If DEFAULT is nil then return empty string for empty input." (completing-read (format-prompt prompt default) (lambda (string pred action) (if (eq action 'metadata) - '(metadata (category . bookmark)) + '(metadata + (category . bookmark) + (narrow-completions-function + . bookmark-narrow-completions-by-type)) (complete-with-action action bookmark-alist string pred))) nil 0 nil 'bookmark-history default)))) +(defun bookmark-narrow-completions-by-type () + "Restrict bookmark completions list to bookmarks of a given type." + (let* ((get-type + (lambda (bmk-record) + (let ((res (bookmark-type-from-full-record bmk-record))) + (if (and res (not (string-empty-p res))) res "Regular")))) + (types (delete-dups (mapcar get-type bookmark-alist))) + (type (completing-read "Keep bookmark completions of type: " + types nil t))) + (cons (lambda (cand &rest _) + (let ((string (cond + ((stringp cand) cand) + ((symbolp cand) (symbol-name cand)) + (t (car cand))))) + (string= type (funcall get-type (assoc string bookmark-alist))))) + (concat "bookmark type " (prin1-to-string + (substring-no-properties type)))))) (defmacro bookmark-maybe-historicize-string (string) "Put STRING into the bookmark prompt history, if caller non-interactive.