# HG changeset patch # User Thierry Volpiatto # Date 1271696126 -7200 # Node ID 450b24a81b9dd4f91e50b2f82cb0fcc81503f70f # Parent 00b16f9f52adab5048a905c78953c49bdfa2e9a2 Allow to bookmark a mail from a Gnus article buffer and retrieve position. * lisp/bookmark.el (bookmark-make-record-default) Avoid recording *-context-string when not needed. * lisp/gnus/gnus-art.el set `bookmark-make-record-function' local. * lisp/gnus/gnus-sum.el (gnus-summary-bookmark-make-record) allow recording from article buffer. (gnus-summary-bookmark-jump) maybe jump to article buffer. diff --git a/lisp/bookmark.el b/lisp/bookmark.el --- a/lisp/bookmark.el +++ b/lisp/bookmark.el @@ -528,26 +528,30 @@ (setq bookmark-current-bookmark stripped-name) (bookmark-bmenu-surreptitiously-rebuild-list))) -(defun bookmark-make-record-default (&optional point-only) +(defun bookmark-make-record-default (&optional point-only pos read-only) "Return the record describing the location of a new bookmark. Must be at the correct position in the buffer in which the bookmark is being set. If POINT-ONLY is non-nil, then only return the subset of the -record that pertains to the location within the buffer." +record that pertains to the location within the buffer. +If READ-ONLY is non-nil that's mean buffer is read-only and +there is no need to record front/rear-context-string, position is enough." `(,@(unless point-only `((filename . ,(bookmark-buffer-file-name)))) - (front-context-string - . ,(if (>= (- (point-max) (point)) bookmark-search-size) - (buffer-substring-no-properties - (point) - (+ (point) bookmark-search-size)) - nil)) - (rear-context-string - . ,(if (>= (- (point) (point-min)) bookmark-search-size) - (buffer-substring-no-properties - (point) - (- (point) bookmark-search-size)) - nil)) - (position . ,(point)))) + ,@(unless read-only `((front-context-string + . ,(if (>= (- (point-max) (point)) + bookmark-search-size) + (buffer-substring-no-properties + (point) + (+ (point) bookmark-search-size)) + nil)))) + ,@(unless read-only `((rear-context-string + . ,(if (>= (- (point) (point-min)) + bookmark-search-size) + (buffer-substring-no-properties + (point) + (- (point) bookmark-search-size)) + nil)))) + (position . ,(or pos (point))))) ;;; File format stuff diff --git a/lisp/gnus/gnus-art.el b/lisp/gnus/gnus-art.el --- a/lisp/gnus/gnus-art.el +++ b/lisp/gnus/gnus-art.el @@ -4446,6 +4446,8 @@ (make-local-variable 'gnus-article-image-alist) (make-local-variable 'gnus-article-charset) (make-local-variable 'gnus-article-ignored-charsets) + (set (make-local-variable 'bookmark-make-record-function) + 'gnus-summary-bookmark-make-record) ;; Prevent Emacs 22 from displaying non-break space with `nobreak-space' ;; face. (set (make-local-variable 'nobreak-char-display) nil) diff --git a/lisp/gnus/gnus-sum.el b/lisp/gnus/gnus-sum.el --- a/lisp/gnus/gnus-sum.el +++ b/lisp/gnus/gnus-sum.el @@ -12648,18 +12648,24 @@ (defun gnus-summary-bookmark-make-record () "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)) - (art (cdr gnus-article-current)) - (head (gnus-summary-article-header art)) - (id (mail-header-id head))) - `(,subject - ,@(bookmark-make-record-default 'point-only) - (location . ,(format "Gnus %s:%d:%s" grp art id)) - (group . ,grp) (article . ,art) - (message-id . ,id) (handler . gnus-summary-bookmark-jump)))) + (let (pos buf) + (unless (and (derived-mode-p 'gnus-summary-mode) gnus-article-current) + (save-restriction ; FIXME is it necessary to widen? + (widen) (setq pos (point))) ; Set position in gnus-article buffer. + (setq buf "art") ; We are recording bookmark from article buffer. + (gnus-article-show-summary)) ; Go back in summary buffer. + ;; We are now recording bookmark from summary buffer. + (unless buf (setq buf "sum")) + (let* ((subject (elt (gnus-summary-article-header) 1)) + (grp (car gnus-article-current)) + (art (cdr gnus-article-current)) + (head (gnus-summary-article-header art)) + (id (mail-header-id head))) + `(,subject + ,@(bookmark-make-record-default 'point-only pos 'read-only) + (location . ,(format "Gnus-%s %s:%d:%s" buf grp art id)) + (group . ,grp) (article . ,art) + (message-id . ,id) (handler . gnus-summary-bookmark-jump))))) ;;;###autoload (defun gnus-summary-bookmark-jump (bookmark) @@ -12667,10 +12673,18 @@ 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))) + (id (bookmark-prop-get bookmark 'message-id)) + (buf (car (split-string (bookmark-prop-get bookmark 'location))))) (gnus-fetch-group group (list article)) (gnus-summary-insert-cached-articles) (gnus-summary-goto-article id nil 'force) + ;; FIXME we have to wait article buffer is ready (only large buffer) + ;; Is there a better solution to know that? + ;; If we don't wait `bookmark-default-handler' will have no chance + ;; to set position. However there is no error, just wrong pos. + (sit-for 1) + (when (string= buf "Gnus-art") + (other-window 1)) (bookmark-default-handler `("" (buffer . ,(current-buffer))