Subject: Re: bug#48683: 28.0.50; [PATCH] Feature suggestion gnus-summary-toggle-mark-as-processable

From: Alex Bochannek <[email-masked]>
Date: Mon, 31 May 2021 13:33:08 -0700

Lars Ingebrigtsen <[email-masked]> writes:

> Alex Bochannek <[email-masked]> writes:
>
>> I can absolutely use `#' and `M-#`, but switching between
>> the two quickly when going through dozens of messages requires a fair
>> amount of dexterity.
>
> It seems like many people would prefer to have the `#' command be a
> toggle.  Perhaps we should just add a user option to have `#' toggle or
> not?  (Defaulting to "not toggle" for backwards compatibility.)

How about something like this?

diff --git a/doc/misc/gnus.texi b/doc/misc/gnus.texi
index 7d6fa4cb5c..b9c6952d60 100644
--- a/doc/misc/gnus.texi
+++ b/doc/misc/gnus.texi
@@ -6618,13 +6618,15 @@ Setting Process Marks
 @kindex M P p @r{(Summary)}
 @findex gnus-summary-mark-as-processable
 Mark the current article with the process mark
-(@code{gnus-summary-mark-as-processable}).
-@findex gnus-summary-unmark-as-processable
+(@code{gnus-summary-mark-as-processable}).@*
+If @code{gnus-summary-process-mark-toggle} is non-nil, toggle the
+existing process mark for the current article.
 
 @item M P u
 @itemx M-#
 @kindex M P u @r{(Summary)}
 @kindex M-# @r{(Summary)}
+@findex gnus-summary-unmark-as-processable
 Remove the process mark, if any, from the current article
 (@code{gnus-summary-unmark-as-processable}).
 
@@ -10569,6 +10571,8 @@ Pick and Read
 it selects just the article.  If given a numerical prefix, go to that
 thread or article and pick it.  (The line number is normally displayed
 at the beginning of the summary pick lines.)
+If @code{gnus-summary-process-mark-toggle} is non-nil, this key will
+unpick an already picked article.
 
 @item @key{SPC}
 @kindex SPC @r{(Pick)}
diff --git a/lisp/gnus/gnus-sum.el b/lisp/gnus/gnus-sum.el
index aa4c753287..941cbaa7d1 100644
--- a/lisp/gnus/gnus-sum.el
+++ b/lisp/gnus/gnus-sum.el
@@ -562,6 +562,12 @@ gnus-move-group-prefix-function
   :group 'gnus-summary-mail
   :type 'function)
 
+(defcustom gnus-summary-process-mark-toggle nil
+  "If non-nil the process mark command toggles the article's mark."
+  :version "28.1"
+  :group 'gnus-summary
+  :type 'boolean)
+
 ;; FIXME: Although the custom type is `character' for the following variables,
 ;; using multibyte characters (Latin-1, UTF-8) doesn't work.  -- rs
 
@@ -2774,7 +2780,7 @@ gnus-summary-make-menu-bar
 	 ["Hide marked" gnus-summary-limit-exclude-marks t]
 	 ["Show expunged" gnus-summary-limit-include-expunged t])
 	("Process Mark"
-	 ["Set mark" gnus-summary-mark-as-processable t]
+	 ["Set/Toggle mark" gnus-summary-mark-as-processable t]
 	 ["Remove mark" gnus-summary-unmark-as-processable t]
 	 ["Remove all marks" gnus-summary-unmark-all-processable t]
 	 ["Invert marks" gnus-uu-invert-processable t]
@@ -10951,10 +10957,14 @@ gnus-summary-mark-as-processable
 	  (n (abs n)))
       (while (and
 	      (> n 0)
-	      (if unmark
-		  (gnus-summary-remove-process-mark
-		   (gnus-summary-article-number))
-		(gnus-summary-set-process-mark (gnus-summary-article-number)))
+	      (let ((article (gnus-summary-article-number)))
+		(if (eq t unmark)
+		    (gnus-summary-remove-process-mark article)
+		  (if (eq t gnus-summary-process-mark-toggle)
+		      (if (memq article gnus-newsgroup-processable)
+			  (gnus-summary-remove-process-mark article)
+			(gnus-summary-set-process-mark article))
+		    (gnus-summary-set-process-mark article))))
 	      (zerop (gnus-summary-next-subject (if backward -1 1) nil t)))
 	(setq n (1- n)))
       (when (/= 0 n)

-- 
Alex.