unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
* [PATCH v2 0/3] Allow emacs to toggle display of all parts including multipart
@ 2012-12-03  0:58 Mark Walters
  2012-12-03  0:58 ` [PATCH v2 1/3] emacs: show: make refresh fix point(ish) Mark Walters
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Mark Walters @ 2012-12-03  0:58 UTC (permalink / raw)
  To: notmuch

This is rather more polished version of
id:1351152563-27277-1-git-send-email-markwalters1009@gmail.com.

The first patch modifies the behaviour of show refresh buffer to keep
state more accurately where possible. It can never be perfect but it
makes a reasonable attempt. This is independent of patches 2 and 3.

The second patch allows the user to toggle the visibility of any part
with 't' on the part button. It does this by storing a list of all
parts that the user has over-ruled.

The final patch binds the toggle to the default action in cases where
the part has no filename. Is this a reasonable heuristic? And should
it be customisable? In all cases the defined actions (save, view,
other, and toggle) always do their action (ie they do not apply any
heuristics)

Overall I am pleased with the way it works. The one caveat is that it
does redisplay the whole buffer when toggling the parts: it might be
nice to use invisibility but that is beyond my lisp. Moreover it could
be added at a later stage without changing the user experience.


Best wishes

Mark


Mark Walters (3):
  emacs: show: make refresh fix point(ish)
  emacs: allow the user to toggle the visibility of
    multipart/alternative parts
  emacs: show make default part button toggle view when sensible

 emacs/notmuch-show.el |   80 ++++++++++++++++++++++++++++++++++++++----------
 1 files changed, 63 insertions(+), 17 deletions(-)

-- 
1.7.9.1

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

* [PATCH v2 1/3] emacs: show: make refresh fix point(ish)
  2012-12-03  0:58 [PATCH v2 0/3] Allow emacs to toggle display of all parts including multipart Mark Walters
@ 2012-12-03  0:58 ` Mark Walters
  2012-12-03  0:58 ` [PATCH v2 2/3] emacs: allow the user to toggle the visibility of multipart/alternative parts Mark Walters
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Mark Walters @ 2012-12-03  0:58 UTC (permalink / raw)
  To: notmuch

This makes a moderate attempt to keep the screen and point in the same
place when refreshing (unless we are resetting state). It does this by
moving to the same point relative to the start of the message, and
moving that to the same line position in the screen relative to the
top of the window.

This fixes some mild annoyances like the whole message resetting when
toggling indentation when reading a diff (ie currently you lose your
place). It also makes the follow up patches in this series for
toggling parts work much more nicely.
---
 emacs/notmuch-show.el |   25 ++++++++++++++++++-------
 1 files changed, 18 insertions(+), 7 deletions(-)

diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el
index 489e32c..cc0487c 100644
--- a/emacs/notmuch-show.el
+++ b/emacs/notmuch-show.el
@@ -1137,8 +1137,13 @@ function is used."
 
 This includes:
  - the list of open messages,
- - the current message."
-  (list (notmuch-show-get-message-id) (notmuch-show-get-message-ids-for-open-messages)))
+ - the current message
+ - point relative to the top of this message
+ - current line number on screen of point."
+  (list (count-lines (window-start) (point))
+	(- (point) (notmuch-show-message-top))
+	(notmuch-show-get-message-id)
+	(notmuch-show-get-message-ids-for-open-messages)))
 
 (defun notmuch-show-apply-state (state)
   "Apply STATE to the current buffer.
@@ -1147,8 +1152,10 @@ This includes:
  - opening the messages previously opened,
  - closing all other messages,
  - moving to the correct current message."
-  (let ((current (car state))
-	(open (cadr state)))
+  (let* ((height (pop state))
+	 (relative-point (pop state))
+	 (current (pop state))
+	 (open (pop state)))
 
     ;; Open those that were open.
     (goto-char (point-min))
@@ -1158,12 +1165,16 @@ This includes:
 
     ;; Go to the previously open message.
     (goto-char (point-min))
-    (unless (loop if (string= current (notmuch-show-get-message-id))
+    (if (loop if (string= current (notmuch-show-get-message-id))
 		  return t
 		  until (not (notmuch-show-goto-message-next)))
+	(progn
+	  (notmuch-show-message-adjust)
+	  (forward-char relative-point)
+	  (recenter height))
       (goto-char (point-min))
-      (message "Previously current message not found."))
-    (notmuch-show-message-adjust)))
+      (message "Previously current message not found.")
+      (notmuch-show-message-adjust))))
 
 (defun notmuch-show-refresh-view (&optional reset-state)
   "Refresh the current view.
-- 
1.7.9.1

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

* [PATCH v2 2/3] emacs: allow the user to toggle the visibility of multipart/alternative parts
  2012-12-03  0:58 [PATCH v2 0/3] Allow emacs to toggle display of all parts including multipart Mark Walters
  2012-12-03  0:58 ` [PATCH v2 1/3] emacs: show: make refresh fix point(ish) Mark Walters
@ 2012-12-03  0:58 ` Mark Walters
  2012-12-03  0:58 ` [PATCH v2 3/3] emacs: show make default part button toggle view when sensible Mark Walters
  2012-12-03 22:45 ` [PATCH v2 0/3] Allow emacs to toggle display of all parts including multipart Mark Walters
  3 siblings, 0 replies; 5+ messages in thread
From: Mark Walters @ 2012-12-03  0:58 UTC (permalink / raw)
  To: notmuch

This patch adds a keybinding to the buttons in the notmuch-show emacs
buffer to allow the user to toggle the visibility of each part of a
message in the show buffer.  This is particularly useful for
multipart/alternative parts where the parts are not really
alternatives but contain different information.
---
 emacs/notmuch-show.el |   48 +++++++++++++++++++++++++++++++++++++++---------
 1 files changed, 39 insertions(+), 9 deletions(-)

diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el
index cc0487c..9a33d28 100644
--- a/emacs/notmuch-show.el
+++ b/emacs/notmuch-show.el
@@ -154,6 +154,11 @@ indentation."
 (make-variable-buffer-local 'notmuch-show-indent-content)
 (put 'notmuch-show-indent-content 'permanent-local t)
 
+(defvar notmuch-show-message-multipart/alternative-display-parts nil
+  "A list of message-ids/parts where the user has overridden notmuch display choice")
+(make-variable-buffer-local 'notmuch-show-message-multipart/alternative-display-parts)
+(put 'notmuch-show-message-multipart/alternative-display-parts 'permanent-local t)
+
 (defcustom notmuch-show-stash-mlarchive-link-alist
   '(("Gmane" . "http://mid.gmane.org/")
     ("MARC" . "http://marc.info/?i=")
@@ -469,6 +474,7 @@ message at DEPTH in the current thread."
     (define-key map "v" 'notmuch-show-part-button-view)
     (define-key map "o" 'notmuch-show-part-button-interactively-view)
     (define-key map "|" 'notmuch-show-part-button-pipe)
+    (define-key map "t" 'notmuch-show-part-button-internally-show)
     map)
   "Submap for button commands")
 (fset 'notmuch-show-part-button-map notmuch-show-part-button-map)
@@ -545,6 +551,16 @@ message at DEPTH in the current thread."
     (let ((handle (mm-make-handle (current-buffer) (list content-type))))
       (mm-pipe-part handle))))
 
+(defun notmuch-show-internally-show-part (message-id nth &optional filename content-type)
+  "Set a part to be displayed internally"
+  (let ((current-parts (lax-plist-get notmuch-show-message-multipart/alternative-display-parts message-id)))
+    (setq notmuch-show-message-multipart/alternative-display-parts
+	  (lax-plist-put notmuch-show-message-multipart/alternative-display-parts message-id
+			 (if (memq nth current-parts)
+			     (delq nth current-parts)
+			   (cons nth current-parts)))))
+  (notmuch-show-refresh-view))
+
 (defun notmuch-show-multipart/*-to-list (part)
   (mapcar (lambda (inner-part) (plist-get inner-part :content-type))
 	  (plist-get part :content)))
@@ -557,12 +573,12 @@ message at DEPTH in the current thread."
     ;; This inserts all parts of the chosen type rather than just one,
     ;; but it's not clear that this is the wrong thing to do - which
     ;; should be chosen if there are more than one that match?
+
     (mapc (lambda (inner-part)
 	    (let ((inner-type (plist-get inner-part :content-type)))
-	      (if (or notmuch-show-all-multipart/alternative-parts
-		      (string= chosen-type inner-type))
-		  (notmuch-show-insert-bodypart msg inner-part depth)
-		(notmuch-show-insert-part-header (plist-get inner-part :id) inner-type inner-type nil " (not shown)"))))
+	      (notmuch-show-insert-bodypart msg inner-part depth
+					    (not (or notmuch-show-all-multipart/alternative-parts
+						     (string= chosen-type inner-type))))))
 	  inner-parts)
 
     (when notmuch-show-indent-multipart
@@ -830,11 +846,20 @@ message at DEPTH in the current thread."
       (setq handlers (cdr handlers))))
   t)
 
-(defun notmuch-show-insert-bodypart (msg part depth)
-  "Insert the body part PART at depth DEPTH in the current thread."
-  (let ((content-type (downcase (plist-get part :content-type)))
+(defun notmuch-show-insert-bodypart (msg part depth &optional not-shown)
+  "Insert the body part PART at depth DEPTH in the current thread.
+
+If not-shown is TRUE then do not show the part unless the user
+has overridden the default for this part"
+  (let ((user-parts (lax-plist-get notmuch-show-message-multipart/alternative-display-parts
+				   (notmuch-id-to-query (plist-get msg :id))))
+	(content-type (downcase (plist-get part :content-type)))
 	(nth (plist-get part :id)))
-    (notmuch-show-insert-bodypart-internal msg part content-type nth depth content-type))
+    (when (memq nth user-parts)
+      (setq not-shown (not not-shown)))
+    (if not-shown
+	(notmuch-show-insert-part-header nth content-type content-type nil " (not shown)")
+      (notmuch-show-insert-bodypart-internal msg part content-type nth depth content-type)))
   ;; Some of the body part handlers leave point somewhere up in the
   ;; part, so we make sure that we're down at the end.
   (goto-char (point-max))
@@ -1185,7 +1210,8 @@ non-nil) then the state of the buffer (open/closed messages) is
 reset based on the original query."
   (interactive "P")
   (let ((inhibit-read-only t)
-	(state (unless reset-state
+	(state (if reset-state
+		   (setq notmuch-show-message-multipart/alternative-display-parts nil)
 		 (notmuch-show-capture-state))))
     (erase-buffer)
     (notmuch-show-build-buffer)
@@ -1980,6 +2006,10 @@ the user (see `notmuch-show-stash-mlarchive-link-alist')."
   (interactive)
   (notmuch-show-part-button-internal button #'notmuch-show-pipe-part))
 
+(defun notmuch-show-part-button-internally-show (&optional button)
+  (interactive)
+  (notmuch-show-part-button-internal button #'notmuch-show-internally-show-part))
+
 (defun notmuch-show-part-button-internal (button handler)
   (let ((button (or button (button-at (point)))))
     (if button
-- 
1.7.9.1

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

* [PATCH v2 3/3] emacs: show make default part button toggle view when sensible
  2012-12-03  0:58 [PATCH v2 0/3] Allow emacs to toggle display of all parts including multipart Mark Walters
  2012-12-03  0:58 ` [PATCH v2 1/3] emacs: show: make refresh fix point(ish) Mark Walters
  2012-12-03  0:58 ` [PATCH v2 2/3] emacs: allow the user to toggle the visibility of multipart/alternative parts Mark Walters
@ 2012-12-03  0:58 ` Mark Walters
  2012-12-03 22:45 ` [PATCH v2 0/3] Allow emacs to toggle display of all parts including multipart Mark Walters
  3 siblings, 0 replies; 5+ messages in thread
From: Mark Walters @ 2012-12-03  0:58 UTC (permalink / raw)
  To: notmuch

When the part has no filename it is reasonable to guess it is not a
part for saving or other normal attachment things so default to
toggling viewability. Possibly this should be customisable but the 4
main actions (save, view, open with, toggle viewability) all force
that particular action so it is easy for the user to get round if we
do make a mistake.
---
 emacs/notmuch-show.el |    7 ++++++-
 1 files changed, 6 insertions(+), 1 deletions(-)

diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el
index 9a33d28..c8c1657 100644
--- a/emacs/notmuch-show.el
+++ b/emacs/notmuch-show.el
@@ -1988,7 +1988,12 @@ the user (see `notmuch-show-stash-mlarchive-link-alist')."
 
 (defun notmuch-show-part-button-default (&optional button)
   (interactive)
-  (notmuch-show-part-button-internal button notmuch-show-part-button-default-action))
+  (let* ((button (or button (button-at (point))))
+	 (filename (and button (button-get button :notmuch-filename)))
+	 (handler (if filename
+		      notmuch-show-part-button-default-action
+		    #'notmuch-show-internally-show-part)))
+    (notmuch-show-part-button-internal button handler)))
 
 (defun notmuch-show-part-button-save (&optional button)
   (interactive)
-- 
1.7.9.1

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

* Re: [PATCH v2 0/3] Allow emacs to toggle display of all parts including multipart
  2012-12-03  0:58 [PATCH v2 0/3] Allow emacs to toggle display of all parts including multipart Mark Walters
                   ` (2 preceding siblings ...)
  2012-12-03  0:58 ` [PATCH v2 3/3] emacs: show make default part button toggle view when sensible Mark Walters
@ 2012-12-03 22:45 ` Mark Walters
  3 siblings, 0 replies; 5+ messages in thread
From: Mark Walters @ 2012-12-03 22:45 UTC (permalink / raw)
  To: notmuch


Hi

I now have a version which does this `right': using invisibility as with
citations and signatures etc. It is working but I need to look through
more carefully before posting.

Best wishes

Mark

On Mon, 03 Dec 2012, Mark Walters <markwalters1009@gmail.com> wrote:
> This is rather more polished version of
> id:1351152563-27277-1-git-send-email-markwalters1009@gmail.com.
>
> The first patch modifies the behaviour of show refresh buffer to keep
> state more accurately where possible. It can never be perfect but it
> makes a reasonable attempt. This is independent of patches 2 and 3.
>
> The second patch allows the user to toggle the visibility of any part
> with 't' on the part button. It does this by storing a list of all
> parts that the user has over-ruled.
>
> The final patch binds the toggle to the default action in cases where
> the part has no filename. Is this a reasonable heuristic? And should
> it be customisable? In all cases the defined actions (save, view,
> other, and toggle) always do their action (ie they do not apply any
> heuristics)
>
> Overall I am pleased with the way it works. The one caveat is that it
> does redisplay the whole buffer when toggling the parts: it might be
> nice to use invisibility but that is beyond my lisp. Moreover it could
> be added at a later stage without changing the user experience.
>
>
> Best wishes
>
> Mark
>
>
> Mark Walters (3):
>   emacs: show: make refresh fix point(ish)
>   emacs: allow the user to toggle the visibility of
>     multipart/alternative parts
>   emacs: show make default part button toggle view when sensible
>
>  emacs/notmuch-show.el |   80 ++++++++++++++++++++++++++++++++++++++----------
>  1 files changed, 63 insertions(+), 17 deletions(-)
>
> -- 
> 1.7.9.1

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

end of thread, other threads:[~2012-12-03 22:45 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-12-03  0:58 [PATCH v2 0/3] Allow emacs to toggle display of all parts including multipart Mark Walters
2012-12-03  0:58 ` [PATCH v2 1/3] emacs: show: make refresh fix point(ish) Mark Walters
2012-12-03  0:58 ` [PATCH v2 2/3] emacs: allow the user to toggle the visibility of multipart/alternative parts Mark Walters
2012-12-03  0:58 ` [PATCH v2 3/3] emacs: show make default part button toggle view when sensible Mark Walters
2012-12-03 22:45 ` [PATCH v2 0/3] Allow emacs to toggle display of all parts including multipart Mark Walters

Code repositories for project(s) associated with this public inbox

	https://yhetil.org/notmuch.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).