all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* enhancement to bookmark.el
@ 2004-06-08 20:33 David J. Biesack
  0 siblings, 0 replies; 2+ messages in thread
From: David J. Biesack @ 2004-06-08 20:33 UTC (permalink / raw)



I have an enhancement request for bookmark.el.

Bookmark's menu mode does not have a key/command for moving the file.
The below adds this, as well as an interactive bookmark-move command.
I'm not particularly happy with the key binding, but 'm' (for 'move) 
and 'r' (rename0 are already taken.

;; Add a "Move" action to bookmark-bmenu, to move a bookmark to a new file
;; David.Biesack@sas.com

(defun bookmark-bmenu-move ()
  "Move bookmark on current line.  Prompts for a new filename."
  (interactive)
  (if (bookmark-bmenu-check-position)
      (let ((bmrk (bookmark-bmenu-bookmark))
            (thispoint (point)))
        ;; could also invoke
        ;(bookmark-relocate bmrk)
        ;; but that only prompts for the directory name; sometimes
        ;; bookmarked file names change as well.
        (bookmark-move bmrk)
        (bookmark-bmenu-list)
        (goto-char thispoint))))

(defun bookmark-move (name &optional to)
  (interactive (bookmark-completing-read "Move bookmark: "))
  (bookmark-maybe-load-default-file)

  (setq bookmark-current-point (point))
  (setq bookmark-yank-point (point))
  (setq bookmark-current-buffer (current-buffer))
  (let ((newname
         (or to   ; use second arg, if non-nil
             (read-from-minibuffer
              "Move to: "
              (bookmark-get-filename name)
              (let ((now-map (copy-keymap minibuffer-local-map)))
                (define-key now-map  "\C-w" 'bookmark-yank-word)
                now-map)
              nil
              'bookmark-history))))
    (bookmark-set-filename name newname)
    (setq bookmark-current-bookmark name)
    (bookmark-bmenu-surreptitiously-rebuild-list)
    (setq bookmark-alist-modification-count
          (1+ bookmark-alist-modification-count))
    (if (bookmark-time-to-save-p)
        (bookmark-save))))

(define-key bookmark-bmenu-mode-map "M" 'bookmark-bmenu-move)



-- 
David J. Biesack     SAS Institute Inc.
R&D Java Strategist  SAS Campus Drive Cary, NC 27513
(919) 531-7771       http://www.sas.com

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: enhancement to bookmark.el
@ 2004-06-12 19:43 Karl Fogel
  0 siblings, 0 replies; 2+ messages in thread
From: Karl Fogel @ 2004-06-12 19:43 UTC (permalink / raw)
  Cc: emacs-devel

"David J. Biesack" <David.Biesack@sas.com> writes:
> I have an enhancement request for bookmark.el.
> 
> Bookmark's menu mode does not have a key/command for moving the file.
> The below adds this, as well as an interactive bookmark-move command.
> I'm not particularly happy with the key binding, but 'm' (for 'move) 
> and 'r' (rename0 are already taken.

Thank you!  It seems like a good enhancement; I've committed it to
Emacs, though using somewhat different code.

I called the new bmenu function `bookmark-bmenu-relocate', and bound
it to "R", not "M".

Aside from the renaming, I rewrote the function to document what it
does better, and to use `bookmark-relocate' instead of writing
equivalent code.  (Your comment indicated that you thought
bookmark-relocate only prompts for the directory.  In fact, it prompts
for a new file -- the directory is just the default base string for
the completion).

I didn't include the new function `bookmark-move' at all, since we
have `bookmark-relocate'.  If `bookmark-relocate' is missing some
functionality, let's just try to fix it there, no need to add a new
function.

Below is the patch I committed.  Note the doc string updates, the
binding of the new function in the same place as the other bindings,
and the factorization of the bookmark-alist save checking.  Following
the patch is your original mail, for easy comparison.

Best,
-Karl Fogel

Index: ChangeLog
===================================================================
RCS file: /cvsroot/emacs/emacs/lisp/ChangeLog,v
retrieving revision 1.6147
diff -u -r1.6147 ChangeLog
--- ChangeLog	8 Jun 2004 00:35:48 -0000	1.6147
+++ ChangeLog	13 Jun 2004 01:54:38 -0000
@@ -1,3 +1,11 @@
+2004-06-12  Karl Fogel  <kfogel@red-bean.com>
+
+	* bookmark.el (bookmark-bmenu-relocate): New function, as
+	suggested by David J. Biesack <David.Biesack@sas.com>.
+	(bookmark-bmenu-mode-map): Bind `bookmark-bmenu-relocate' to "R".
+	(bookmark-bmenu-mode): Describe binding in doc string.
+	(bookmark-set-filename): Save the bookmark list if it's time.
+
 2004-06-07  Karl Fogel  <kfogel@red-bean.com>
 
 	* saveplace.el (save-place-alist-to-file): Bind `print-length'
Index: bookmark.el
===================================================================
RCS file: /cvsroot/emacs/emacs/lisp/bookmark.el,v
retrieving revision 1.68
diff -u -r1.68 bookmark.el
--- bookmark.el	15 Apr 2004 23:12:21 -0000	1.68
+++ bookmark.el	13 Jun 2004 01:54:40 -0000
@@ -376,7 +376,11 @@
     (if cell
         (setcdr cell filename)
       (nconc (bookmark-get-bookmark-record bookmark)
-             (list (cons 'filename filename))))))
+             (list (cons 'filename filename))))
+    (setq bookmark-alist-modification-count
+          (1+ bookmark-alist-modification-count))
+    (if (bookmark-time-to-save-p)
+        (bookmark-save))))
 
 
 (defun bookmark-get-position (bookmark)
@@ -1491,6 +1495,7 @@
   (define-key bookmark-bmenu-mode-map "m" 'bookmark-bmenu-mark)
   (define-key bookmark-bmenu-mode-map "l" 'bookmark-bmenu-load)
   (define-key bookmark-bmenu-mode-map "r" 'bookmark-bmenu-rename)
+  (define-key bookmark-bmenu-mode-map "R" 'bookmark-bmenu-relocate)
   (define-key bookmark-bmenu-mode-map "t" 'bookmark-bmenu-toggle-filenames)
   (define-key bookmark-bmenu-mode-map "a" 'bookmark-bmenu-show-annotation)
   (define-key bookmark-bmenu-mode-map "A" 'bookmark-bmenu-show-all-annotations)
@@ -1589,6 +1594,7 @@
   so the bookmark menu bookmark remains visible in its window.
 \\[bookmark-bmenu-switch-other-window] -- switch the other window to this bookmark.
 \\[bookmark-bmenu-rename] -- rename this bookmark \(prompts for new name\).
+\\[bookmark-bmenu-relocate] -- relocate this bookmark's file \(prompts for new file\).
 \\[bookmark-bmenu-delete] -- mark this bookmark to be deleted, and move down.
 \\[bookmark-bmenu-delete-backwards] -- mark this bookmark to be deleted, and move up.
 \\[bookmark-bmenu-execute-deletions] -- delete bookmarks marked with `\\[bookmark-bmenu-delete]'.
@@ -2041,6 +2047,15 @@
       (let ((bmrk (bookmark-bmenu-bookmark)))
         (message (bookmark-location bmrk)))))
 
+(defun bookmark-bmenu-relocate ()
+  "Change the file path of the bookmark on the current line,
+  prompting with completion for the new path."
+  (interactive)
+  (if (bookmark-bmenu-check-position)
+      (let ((bmrk (bookmark-bmenu-bookmark))
+            (thispoint (point)))
+        (bookmark-relocate bmrk)
+        (goto-char thispoint))))
 
 \f
 ;;; Menu bar stuff.  Prefix is "bookmark-menu".

########################################################################
And your original mail:
########################################################################

> From: "David J. Biesack" <David.Biesack@sas.com>
> Subject: enhancement to bookmark.el
> To: bug-gnu-emacs@gnu.org
> Date: Tue, 8 Jun 2004 16:33:46 -0400 (EDT)
> 
> 
> I have an enhancement request for bookmark.el.
> 
> Bookmark's menu mode does not have a key/command for moving the file.
> The below adds this, as well as an interactive bookmark-move command.
> I'm not particularly happy with the key binding, but 'm' (for 'move) 
> and 'r' (rename0 are already taken.
> 
> ;; Add a "Move" action to bookmark-bmenu, to move a bookmark to a new file
> ;; David.Biesack@sas.com
> 
> (defun bookmark-bmenu-move ()
>   "Move bookmark on current line.  Prompts for a new filename."
>   (interactive)
>   (if (bookmark-bmenu-check-position)
>       (let ((bmrk (bookmark-bmenu-bookmark))
>             (thispoint (point)))
>         ;; could also invoke
>         ;(bookmark-relocate bmrk)
>         ;; but that only prompts for the directory name; sometimes
>         ;; bookmarked file names change as well.
>         (bookmark-move bmrk)
>         (bookmark-bmenu-list)
>         (goto-char thispoint))))
> 
> (defun bookmark-move (name &optional to)
>   (interactive (bookmark-completing-read "Move bookmark: "))
>   (bookmark-maybe-load-default-file)
> 
>   (setq bookmark-current-point (point))
>   (setq bookmark-yank-point (point))
>   (setq bookmark-current-buffer (current-buffer))
>   (let ((newname
>          (or to   ; use second arg, if non-nil
>              (read-from-minibuffer
>               "Move to: "
>               (bookmark-get-filename name)
>               (let ((now-map (copy-keymap minibuffer-local-map)))
>                 (define-key now-map  "\C-w" 'bookmark-yank-word)
>                 now-map)
>               nil
>               'bookmark-history))))
>     (bookmark-set-filename name newname)
>     (setq bookmark-current-bookmark name)
>     (bookmark-bmenu-surreptitiously-rebuild-list)
>     (setq bookmark-alist-modification-count
>           (1+ bookmark-alist-modification-count))
>     (if (bookmark-time-to-save-p)
>         (bookmark-save))))
> 
> (define-key bookmark-bmenu-mode-map "M" 'bookmark-bmenu-move)
> 
> 
> 
> - -- 
> David J. Biesack     SAS Institute Inc.
> R&D Java Strategist  SAS Campus Drive Cary, NC 27513
> (919) 531-7771       http://www.sas.com

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2004-06-12 19:43 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-06-12 19:43 enhancement to bookmark.el Karl Fogel
  -- strict thread matches above, loose matches on Subject: below --
2004-06-08 20:33 David J. Biesack

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.