From 17db59cbb7e060bed4c181f459b80cb67c1163b5 Mon Sep 17 00:00:00 2001 From: Jamie Beardslee Date: Sun, 21 Jun 2020 06:59:12 +1200 Subject: [PATCH] Add user option to disable location in bookmarks When `bookmark-use-location' set to nil, bookmark-default-handler won't try to jump to the right location in the file. This way bookmarks can be used to just save regularly used files, and save-place (or similar) can be relied on to, well, save the place. --- lisp/bookmark.el | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/lisp/bookmark.el b/lisp/bookmark.el index 5bb1698171..3687a0b20f 100644 --- a/lisp/bookmark.el +++ b/lisp/bookmark.el @@ -170,6 +170,10 @@ bookmark-menu-heading "Face used to highlight the heading in bookmark menu buffers." :version "22.1") +(defcustom bookmark-use-location t + "Whether to open the specific location of bookmarked files. +See also `save-place-mode'." + :type 'boolean) ;;; No user-serviceable parts beyond this point. @@ -1224,16 +1228,17 @@ bookmark-default-handler ((and buf (get-buffer buf))) (t ;; If not, raise error. (signal 'bookmark-error-no-filename (list 'stringp file))))) - (if place (goto-char place)) - ;; Go searching forward first. Then, if forward-str exists and - ;; was found in the file, we can search backward for behind-str. - ;; Rationale is that if text was inserted between the two in the - ;; file, it's better to be put before it so you can read it, - ;; rather than after and remain perhaps unaware of the changes. - (when (and forward-str (search-forward forward-str (point-max) t)) - (goto-char (match-beginning 0))) - (when (and behind-str (search-backward behind-str (point-min) t)) - (goto-char (match-end 0))) + (when bookmark-use-location + (if place (goto-char place)) + ;; Go searching forward first. Then, if forward-str exists and + ;; was found in the file, we can search backward for behind-str. + ;; Rationale is that if text was inserted between the two in the + ;; file, it's better to be put before it so you can read it, + ;; rather than after and remain perhaps unaware of the changes. + (when (and forward-str (search-forward forward-str (point-max) t)) + (goto-char (match-beginning 0))) + (when (and behind-str (search-backward behind-str (point-min) t)) + (goto-char (match-end 0)))) nil)) ;;;###autoload -- 2.27.0