X-Git-Url: https://git.hcoop.net/bpt/emacs.git/blobdiff_plain/1ec4b7b25979ff9ea72a3ea35bf35d5882f467f7..f1806c78f4da16f9f0123eddac86246ccfa960da:/lisp/bookmark.el diff --git a/lisp/bookmark.el b/lisp/bookmark.el index bf2ea9a951..75a8d9f59d 100644 --- a/lisp/bookmark.el +++ b/lisp/bookmark.el @@ -33,7 +33,7 @@ ;;; Code: (require 'pp) -(eval-when-compile (require 'cl)) +(eval-when-compile (require 'cl-lib)) ;;; Misc comments: ;; @@ -277,8 +277,8 @@ through a file easier.") (defvar bookmark-current-buffer nil "The buffer in which a bookmark is currently being set or renamed. Functions that insert strings into the minibuffer use this to know -the source buffer for that information; see `bookmark-yank-word' and -`bookmark-insert-current-bookmark' for example.") +the source buffer for that information; see `bookmark-yank-word' +for example.") (defvar bookmark-yank-point 0 @@ -473,6 +473,12 @@ equivalently just return ALIST without NAME.") (defun bookmark-make-record () "Return a new bookmark record (NAME . ALIST) for the current location." (let ((record (funcall bookmark-make-record-function))) + ;; Set up defaults. + (bookmark-prop-set + record 'defaults + (delq nil (delete-dups (append (bookmark-prop-get record 'defaults) + (list bookmark-current-bookmark + (bookmark-buffer-name)))))) ;; Set up default name. (if (stringp (car record)) ;; The function already provided a default name. @@ -738,10 +744,6 @@ This expects to be called from `point-min' in a bookmark file." (let ((map (make-sparse-keymap))) (set-keymap-parent map minibuffer-local-map) (define-key map "\C-w" 'bookmark-yank-word) - ;; This C-u binding might not be very useful any more now that we - ;; provide access to the default via the standard M-n binding. - ;; Maybe we should just remove it? --Stef-08 - (define-key map "\C-u" 'bookmark-insert-current-bookmark) map)) ;;;###autoload @@ -772,7 +774,19 @@ the list of bookmarks.)" (interactive (list nil current-prefix-arg)) (unwind-protect (let* ((record (bookmark-make-record)) - (default (car record))) + ;; `defaults' is a transient element of the + ;; extensible format described above in the section + ;; `File format stuff'. Bookmark record functions + ;; can use it to specify a list of default values + ;; accessible via M-n while reading a bookmark name. + (defaults (bookmark-prop-get record 'defaults)) + (default (if (consp defaults) (car defaults) defaults))) + + (if defaults + ;; Don't store default values in the record. + (setq record (assq-delete-all 'defaults record)) + ;; When no defaults in the record, use its first element. + (setq defaults (car record) default defaults)) (bookmark-maybe-load-default-file) ;; Don't set `bookmark-yank-point' and `bookmark-current-buffer' @@ -788,7 +802,7 @@ the list of bookmarks.)" (format "Set bookmark (%s): " default) nil bookmark-minibuffer-read-name-map - nil nil default)))) + nil nil defaults)))) (and (string-equal str "") (setq str default)) (bookmark-store str (cdr record) no-overwrite) @@ -888,18 +902,6 @@ Lines beginning with `#' are ignored." (bookmark-edit-annotation-mode bookmark-name-or-record)) -(defun bookmark-insert-current-bookmark () - "Insert into the bookmark name currently being set the value of -`bookmark-current-bookmark' in `bookmark-current-buffer', defaulting -to the buffer's file name if `bookmark-current-bookmark' is nil." - (interactive) - (let ((str - (with-current-buffer bookmark-current-buffer - (or bookmark-current-bookmark - (bookmark-buffer-name))))) - (insert str))) - - (defun bookmark-buffer-name () "Return the name of the current buffer in a form usable as a bookmark name. If the buffer is associated with a file or directory, use that name." @@ -2015,11 +2017,11 @@ To carry out the deletions that you've marked, use \\\\ (tmp-list ())) (while (let ((char (read-key (concat prompt bookmark-search-pattern)))) - (case char - ((?\e ?\r) nil) ; RET or ESC break the search loop. + (pcase char + ((or ?\e ?\r) nil) ; RET or ESC break the search loop. (?\C-g (setq bookmark-quit-flag t) nil) (?\d (pop tmp-list) t) ; Delete last char of pattern with DEL - (t + (_ (if (characterp char) (push char tmp-list) (setq unread-command-events @@ -2034,9 +2036,9 @@ To carry out the deletions that you've marked, use \\\\ (defun bookmark-bmenu-filter-alist-by-regexp (regexp) "Filter `bookmark-alist' with bookmarks matching REGEXP and rebuild list." (let ((bookmark-alist - (loop for i in bookmark-alist - when (string-match regexp (car i)) collect i into new - finally return new))) + (cl-loop for i in bookmark-alist + when (string-match regexp (car i)) collect i into new + finally return new))) (bookmark-bmenu-list)))