changeset 107838:f50f5478ec53

Clean up last bookmark changes for man/woman/gnus-summary. * gnus-sum.el: Add bookmark declarations to silence the compiler. (gnus-mark-xrefs-as-read, gnus-summary-limit-to-bodies): Use with-current-buffer to silence the byte-compiler. (gnus-summary-bookmark-make-record): Use derived-mode-p and don't bother to require `gnus'. (gnus-summary-bookmark-jump): Don't forget to autoload. Simplify. * woman.el: Add bookmark declarations to silence the compiler. (bookmark-prop-get): Use `man-args' rather than `filename' as a first step to compatibility between man and woman bookmarks. Adjust for Man-default-bookmark-title renaming. (woman-bookmark-jump): Adjust accordingly. Don't forget to autoload. * man.el: Add bookmark declarations to silence the compiler. (Man-name-local-regexp): Make it match NAME as well. (Man-getpage-in-background): Return the buffer. (Man-notify-when-ready): Use `case'. (man-set-default-bookmark-title): Rename to Man-default-bookmark-title. Don't hardcode "NAME". Simplify. (Man-bookmark-make-record): Use Man-arguments rather than buffer-name. Rename from Man-bookmark-make-record. (Man-bookmark-jump): Rename from man-bookmark-jump. Simplify now that we have the actual man-args. Use Man-getpage-in-background rather than `man' since the arg is already processed. Let bookmark.el do the window handling. Only wait for the relevant process. Don't forget to autoload. * bookmark.el (bookmark-default-file): Use locate-user-emacs-file.
author Stefan Monnier <monnier@iro.umontreal.ca>
date Mon, 12 Apr 2010 12:09:47 -0400
parents 4ad129f7804d
children 117dfaee55b8
files lisp/ChangeLog lisp/bookmark.el lisp/gnus/ChangeLog lisp/gnus/gnus-sum.el lisp/man.el lisp/woman.el
diffstat 6 files changed, 110 insertions(+), 63 deletions(-) [+]
line wrap: on
line diff
--- a/lisp/ChangeLog	Mon Apr 12 11:17:29 2010 -0400
+++ b/lisp/ChangeLog	Mon Apr 12 12:09:47 2010 -0400
@@ -1,3 +1,27 @@
+2010-04-12  Stefan Monnier  <monnier@iro.umontreal.ca>
+
+	* woman.el: Add bookmark declarations to silence the compiler.
+	(bookmark-prop-get): Use `man-args' rather than `filename' as a first
+	step to compatibility between man and woman bookmarks.
+	Adjust for Man-default-bookmark-title renaming.
+	(woman-bookmark-jump): Adjust accordingly.  Don't forget to autoload.
+
+	* man.el: Add bookmark declarations to silence the compiler.
+	(Man-name-local-regexp): Make it match NAME as well.
+	(Man-getpage-in-background): Return the buffer.
+	(Man-notify-when-ready): Use `case'.
+	(man-set-default-bookmark-title): Rename to Man-default-bookmark-title.
+	Don't hardcode "NAME".  Simplify.
+	(Man-bookmark-make-record): Use Man-arguments rather than buffer-name.
+	Rename from Man-bookmark-make-record.
+	(Man-bookmark-jump): Rename from man-bookmark-jump.  Simplify now that
+	we have the actual man-args.  Use Man-getpage-in-background rather
+	than `man' since the arg is already processed.  Let bookmark.el do the
+	window handling.  Only wait for the relevant process.
+	Don't forget to autoload.
+
+	* bookmark.el (bookmark-default-file): Use locate-user-emacs-file.
+
 2010-04-12  Thierry Volpiatto  <thierry.volpiatto@gmail.com>
 
 	* woman.el (woman-bookmark-make-record, woman-bookmark-jump):
--- a/lisp/bookmark.el	Mon Apr 12 11:17:29 2010 -0400
+++ b/lisp/bookmark.el	Mon Apr 12 12:09:47 2010 -0400
@@ -92,7 +92,7 @@
   (if bookmark-file
       ;; In case user set `bookmark-file' in her .emacs:
       bookmark-file
-    (convert-standard-filename "~/.emacs.bmk"))
+    (locate-user-emacs-file "bookmarks" ".emacs.bmk"))
   "File in which to save bookmarks by default."
   :type 'file
   :group 'bookmark)
--- a/lisp/gnus/ChangeLog	Mon Apr 12 11:17:29 2010 -0400
+++ b/lisp/gnus/ChangeLog	Mon Apr 12 12:09:47 2010 -0400
@@ -1,3 +1,12 @@
+2010-04-12  Stefan Monnier  <monnier@iro.umontreal.ca>
+
+	* gnus-sum.el: Add bookmark declarations to silence the compiler.
+	(gnus-mark-xrefs-as-read, gnus-summary-limit-to-bodies):
+	Use with-current-buffer to silence the byte-compiler.
+	(gnus-summary-bookmark-make-record): Use derived-mode-p and don't
+	bother to require `gnus'.
+	(gnus-summary-bookmark-jump): Don't forget to autoload.  Simplify.
+
 2010-04-12  Thierry Volpiatto  <thierry.volpiatto@gmail.com>
 
 	* gnus-sum.el (gnus-summary-bookmark-make-record)
--- a/lisp/gnus/gnus-sum.el	Mon Apr 12 11:17:29 2010 -0400
+++ b/lisp/gnus/gnus-sum.el	Mon Apr 12 12:09:47 2010 -0400
@@ -3017,7 +3017,7 @@
 
 
 (declare-function turn-on-gnus-mailing-list-mode "gnus-ml" ())
-
+(defvar bookmark-make-record-function)
 
 
 (defun gnus-summary-mode (&optional group)
@@ -3072,7 +3072,6 @@
   (gnus-run-mode-hooks 'gnus-summary-mode-hook)
   (turn-on-gnus-mailing-list-mode)
   (mm-enable-multibyte)
-  ;; Bookmark support.
   (set (make-local-variable 'bookmark-make-record-function)
        'gnus-summary-bookmark-make-record)
   (gnus-update-format-specifications nil 'summary 'summary-mode 'summary-dummy)
@@ -6093,8 +6092,7 @@
   "Look through all the headers and mark the Xrefs as read."
   (let ((virtual (gnus-virtual-group-p from-newsgroup))
 	name info xref-hashtb idlist method nth4)
-    (save-excursion
-      (set-buffer gnus-group-buffer)
+    (with-current-buffer gnus-group-buffer
       (when (setq xref-hashtb
 		  (gnus-create-xref-hashtb from-newsgroup headers unreads))
 	(mapatoms
@@ -8344,8 +8342,7 @@
     (dolist (data gnus-newsgroup-data)
       (let (gnus-mark-article-hook)
 	(gnus-summary-select-article t t nil (gnus-data-number data)))
-      (save-excursion
-	(set-buffer gnus-article-buffer)
+      (with-current-buffer gnus-article-buffer
 	(article-goto-body)
 	(let* ((case-fold-search t)
 	       (found (if headersp
@@ -9029,7 +9026,7 @@
       (setq group (format "%s-%d" gnus-newsgroup-name article))
       (gnus-summary-remove-process-mark article)
       (when (gnus-summary-display-article article)
-	(save-excursion
+	(save-excursion ;;What for?
 	  (with-temp-buffer
 	    (insert-buffer-substring gnus-original-article-buffer)
 	    ;; Remove some headers that may lead nndoc to make
@@ -12643,12 +12640,15 @@
 	  (gnus-summary-limit (gnus-sorted-nunion old new))))
     (gnus-summary-position-point)))
 
-;;; BOOKMARK support for GNUS.
+;;; Bookmark support for Gnus.
+(declare-function bookmark-make-record-default "bookmark" (&optional pos-only))
+(declare-function bookmark-prop-get "bookmark" (bookmark prop))
+(declare-function bookmark-default-handler "bookmark" (bmk))
+(declare-function bookmark-get-bookmark-record "bookmark" (bmk))
 
 (defun gnus-summary-bookmark-make-record ()
-  "Make a bookmark entry for a Gnus buffer."
-  (require 'gnus)
-  (unless (and (eq major-mode 'gnus-summary-mode) gnus-article-current)
+  "Make a bookmark entry for a Gnus summary buffer."
+  (unless (and (derived-mode-p 'gnus-summary-mode) gnus-article-current)
     (error "Please retry from the Gnus summary buffer")) ;[1]
   (let* ((subject (elt (gnus-summary-article-header) 1))
          (grp     (car gnus-article-current))
@@ -12660,20 +12660,20 @@
         (group . ,grp) (article . ,art)
         (message-id . ,id) (handler . gnus-summary-bookmark-jump))))
 
-
+;;;###autoload
 (defun gnus-summary-bookmark-jump (bookmark)
   "Handler function for record returned by `gnus-summary-bookmark-make-record'.
 BOOKMARK is a bookmark name or a bookmark record."
   (let ((group    (bookmark-prop-get bookmark 'group))
         (article  (bookmark-prop-get bookmark 'article))
-        (id       (bookmark-prop-get bookmark 'message-id))
-        buf)
+        (id       (bookmark-prop-get bookmark 'message-id)))
     (gnus-fetch-group group (list article))
     (gnus-summary-insert-cached-articles)
     (gnus-summary-goto-article id nil 'force)
-    (setq buf (current-buffer))
     (bookmark-default-handler
-     `("" (buffer . ,buf) . ,(bookmark-get-bookmark-record bookmark)))))
+     `(""
+       (buffer . ,(current-buffer))
+       . ,(bookmark-get-bookmark-record bookmark)))))
 
 (gnus-summary-make-all-marking-commands)
 
--- a/lisp/man.el	Mon Apr 12 11:17:29 2010 -0400
+++ b/lisp/man.el	Mon Apr 12 12:09:47 2010 -0400
@@ -221,8 +221,8 @@
   :type '(repeat string)
   :group 'man)
 
-(defcustom Man-name-local-regexp "^NOM$"
-  "*The translation of the uppercase word NAME in your language.
+(defcustom Man-name-local-regexp (concat "^" (regexp-opt '("NOM" "NAME")) "$")
+  "Regexp that matches the text that precedes the command's name.
 Used in `bookmark-set' to get the default bookmark name."
   :type 'string :group 'bookmark)
 
@@ -888,7 +888,8 @@
     (man man-args)))
 
 (defun Man-getpage-in-background (topic)
-  "Use TOPIC to build and fire off the manpage and cleaning command."
+  "Use TOPIC to build and fire off the manpage and cleaning command.
+Return the buffer in which the manpage will appear."
   (let* ((man-args topic)
 	 (bufname (concat "*Man " man-args "*"))
 	 (buffer  (get-buffer bufname)))
@@ -966,15 +967,16 @@
 			   (format "exited abnormally with code %d"
 				   exit-status)))
 		(setq msg exit-status))
-	    (Man-bgproc-sentinel bufname msg)))))))
+	    (Man-bgproc-sentinel bufname msg)))))
+    buffer))
 
 (defun Man-notify-when-ready (man-buffer)
   "Notify the user when MAN-BUFFER is ready.
 See the variable `Man-notify-method' for the different notification behaviors."
   (let ((saved-frame (with-current-buffer man-buffer
 		       Man-original-frame)))
-    (cond
-     ((eq Man-notify-method 'newframe)
+    (case Man-notify-method
+     (newframe
       ;; Since we run asynchronously, perhaps while Emacs is waiting
       ;; for input, we must not leave a different buffer current.  We
       ;; can't rely on the editor command loop to reselect the
@@ -985,28 +987,27 @@
           (set-window-dedicated-p (frame-selected-window frame) t)
 	  (or (display-multi-frame-p frame)
 	      (select-frame frame)))))
-     ((eq Man-notify-method 'pushy)
+     (pushy
       (switch-to-buffer man-buffer))
-     ((eq Man-notify-method 'bully)
+     (bully
       (and (frame-live-p saved-frame)
 	   (select-frame saved-frame))
       (pop-to-buffer man-buffer)
       (delete-other-windows))
-     ((eq Man-notify-method 'aggressive)
+     (aggressive
       (and (frame-live-p saved-frame)
 	   (select-frame saved-frame))
       (pop-to-buffer man-buffer))
-     ((eq Man-notify-method 'friendly)
+     (friendly
       (and (frame-live-p saved-frame)
 	   (select-frame saved-frame))
       (display-buffer man-buffer 'not-this-window))
-     ((eq Man-notify-method 'polite)
+     (polite
       (beep)
       (message "Manual buffer %s is ready" (buffer-name man-buffer)))
-     ((eq Man-notify-method 'quiet)
+     (quiet
       (message "Manual buffer %s is ready" (buffer-name man-buffer)))
-     ((or (eq Man-notify-method 'meek)
-	  t)
+     (t ;; meek
       (message ""))
      )))
 
@@ -1274,6 +1275,8 @@
 ;; ======================================================================
 ;; set up manual mode in buffer and build alists
 
+(defvar bookmark-make-record-function)
+
 (put 'Man-mode 'mode-class 'special)
 
 (defun Man-mode ()
@@ -1330,9 +1333,8 @@
   (setq imenu-generic-expression (list (list nil Man-heading-regexp 0)))
   (set (make-local-variable 'outline-regexp) Man-heading-regexp)
   (set (make-local-variable 'outline-level) (lambda () 1))
-  ;; Bookmark support.
   (set (make-local-variable 'bookmark-make-record-function)
-       'man-bookmark-make-record)
+       'Man-bookmark-make-record)
   (Man-build-page-list)
   (Man-strip-page-headers)
   (Man-unindent)
@@ -1669,39 +1671,39 @@
     complete-path))
 
 ;;; Bookmark Man Support
+(declare-function bookmark-make-record-default "bookmark" (&optional pos-only))
+(declare-function bookmark-prop-get "bookmark" (bookmark prop))
+(declare-function bookmark-default-handler "bookmark" (bmk))
+(declare-function bookmark-get-bookmark-record "bookmark" (bmk))
 
-(defun man-set-default-bookmark-title ()
-  "Set default bookmark title for Man or woman page based \
-on NAME or `Man-name-local-regexp' entry."
+(defun Man-default-bookmark-title ()
+  "Default bookmark name for Man or WoMan pages.
+Uses `Man-name-local-regexp'."
   (save-excursion
     (goto-char (point-min))
-    (when (or (re-search-forward Man-name-local-regexp nil t)
-              (re-search-forward "^NAME$" nil t))
-      (forward-line 1)
-      (unless (> (skip-chars-forward " ") 0)
-        (skip-chars-forward "\t"))
+    (when (re-search-forward Man-name-local-regexp nil t)
+      (skip-chars-forward "\n\t ")
       (buffer-substring-no-properties (point) (line-end-position)))))
 
-(defun man-bookmark-make-record ()
+(defun Man-bookmark-make-record ()
   "Make a bookmark entry for a Man buffer."
-  `(,(man-set-default-bookmark-title)
+  `(,(Man-default-bookmark-title)
     ,@(bookmark-make-record-default 'point-only)
-      (buffer-name . ,(buffer-name (current-buffer)))
-      (handler . man-bookmark-jump)))
+      (man-args . ,Man-arguments)
+      (handler . Man-bookmark-jump)))
 
-(defun man-bookmark-jump (bookmark)
+;;;###autoload
+(defun Man-bookmark-jump (bookmark)
   "Default bookmark handler for Man buffers."
-  (let* ((buf               (bookmark-prop-get bookmark 'buffer-name))
-         (buf-lst           (split-string buf))
-         (node              (replace-regexp-in-string "\*" "" (car (last buf-lst))))
-         (ind               (when (> (length buf-lst) 2) (second buf-lst)))
-         (Man-notify-method (case bookmark-jump-display-function
-                              ('switch-to-buffer              'pushy)
-                              ('switch-to-buffer-other-window 'friendly)
-                              ('display-buffer                'quiet)
-                              (t                              'friendly))))
-    (man (if ind (format "%s(%s)" node ind) node))
-    (while (get-process "man") (sit-for 1))
+  (let* ((man-args (bookmark-prop-get bookmark 'man-args))
+         ;; Let bookmark.el do the window handling.
+         ;; This let-binding needs to be active during the call to both
+         ;; Man-getpage-in-background and accept-process-output.
+         (Man-notify-method 'meek)
+         (buf (Man-getpage-in-background man-args))
+         (proc (get-buffer-process buf)))
+    (while (and proc (eq (process-status proc) 'run))
+      (accept-process-output proc))
     (bookmark-default-handler
      `("" (buffer . ,buf) . ,(bookmark-get-bookmark-record bookmark)))))
 
--- a/lisp/woman.el	Mon Apr 12 11:17:29 2010 -0400
+++ b/lisp/woman.el	Mon Apr 12 12:09:47 2010 -0400
@@ -1897,6 +1897,7 @@
   (setq woman-emulation value)
   (woman-reformat-last-file))
 
+(defvar bookmark-make-record-function)
 (put 'woman-mode 'mode-class 'special)
 
 (defun woman-mode ()
@@ -4520,18 +4521,29 @@
   nil)					; for woman-file-readable-p etc.
 
 ;;; Bookmark Woman support.
+(declare-function bookmark-make-record-default "bookmark" (&optional pos-only))
+(declare-function bookmark-prop-get "bookmark" (bookmark prop))
+(declare-function bookmark-default-handler "bookmark" (bmk))
+(declare-function bookmark-get-bookmark-record "bookmark" (bmk))
+
+;; FIXME: woman.el and man.el should be better integrated so, for
+;; example, bookmarks of one can be used with the other.
 
 (defun woman-bookmark-make-record ()
   "Make a bookmark entry for a Woman buffer."
-  `(,(man-set-default-bookmark-title)
+  `(,(Man-default-bookmark-title)
     ,@(bookmark-make-record-default 'point-only)
-      (filename . ,woman-last-file-name)
-      (handler . woman-bookmark-jump)))
-
-
+    ;; Use the same form as man's bookmarks, as much as possible.
+    (man-args . ,woman-last-file-name)
+    (handler . woman-bookmark-jump)))
+
+;;;###autoload
 (defun woman-bookmark-jump (bookmark)
   "Default bookmark handler for Woman buffers."
-  (let* ((file (bookmark-prop-get bookmark 'filename))
+  (let* ((file (bookmark-prop-get bookmark 'man-args))
+         ;; FIXME: we need woman-find-file-noselect, since
+         ;; save-window-excursion can't protect us from the case where
+         ;; woman-find-file creates a new frame.
          (buf  (save-window-excursion
                  (woman-find-file file) (current-buffer))))
     (bookmark-default-handler