unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
From: Jonas Bernoulli <jonas@bernoul.li>
To: notmuch@notmuchmail.org
Subject: [PATCH v2 30/36] emacs: avoid unnecessary let-bindings
Date: Sun, 10 Jan 2021 15:01:06 +0100	[thread overview]
Message-ID: <20210110140112.25930-31-jonas@bernoul.li> (raw)
In-Reply-To: <20210110140112.25930-1-jonas@bernoul.li>

To some extend this is a personal preference, but the preference is
strongly dependent on whether one is used to a language that makes it
necessary to use variables like this.

This makes it perfectly clear that we are first getting and then using
a "foo":

  (use-foo (get-foo))

Sure this has to be read "inside out", but that's something one better
gets used to quickly when dealing with lisp.  I don't understand why
one would want to write this instead:

  (let ((the-foo (get-foo)))
    (use-foo the-foo))

Both `get-foo' and `use-foo' are named in a way that make it very
clear that we are dealing with a "foo".  Storing the value in an
additional variable `the-foo' does not make this any more clear.

On the contrary I makes the reader wonder why the author choose to
use a variable.  Is the value used more than once?  Is the value
being retrieved in one context and then used in another (e.g. when
the current buffer changes)?
---
 emacs/notmuch-address.el     |  4 +--
 emacs/notmuch-lib.el         |  6 ++---
 emacs/notmuch-maildir-fcc.el | 10 ++++----
 emacs/notmuch-show.el        | 14 +++++-----
 emacs/notmuch-tag.el         | 10 ++++----
 emacs/notmuch-tree.el        |  5 ++--
 emacs/notmuch.el             | 50 +++++++++++++++++-------------------
 7 files changed, 48 insertions(+), 51 deletions(-)

diff --git a/emacs/notmuch-address.el b/emacs/notmuch-address.el
index 1f22e377..f313c415 100644
--- a/emacs/notmuch-address.el
+++ b/emacs/notmuch-address.el
@@ -260,8 +260,8 @@ (defun notmuch-address-expand-name ()
 ;;; Harvest
 
 (defun notmuch-address-harvest-addr (result)
-  (let ((name-addr (plist-get result :name-addr)))
-    (puthash name-addr t notmuch-address-completions)))
+  (puthash (plist-get result :name-addr)
+	   t notmuch-address-completions))
 
 (defun notmuch-address-harvest-filter (proc string)
   (when (buffer-live-p (process-buffer proc))
diff --git a/emacs/notmuch-lib.el b/emacs/notmuch-lib.el
index 2fd9a27d..cbac8859 100644
--- a/emacs/notmuch-lib.el
+++ b/emacs/notmuch-lib.el
@@ -416,9 +416,9 @@ (defun notmuch-help ()
 its prefixed behavior by setting the 'notmuch-prefix-doc property
 of its command symbol."
   (interactive)
-  (let* ((mode major-mode)
-	 (doc (substitute-command-keys
-	       (notmuch-substitute-command-keys (documentation mode t)))))
+  (let ((doc (substitute-command-keys
+	      (notmuch-substitute-command-keys
+	       (documentation major-mode t)))))
     (with-current-buffer (generate-new-buffer "*notmuch-help*")
       (insert doc)
       (goto-char (point-min))
diff --git a/emacs/notmuch-maildir-fcc.el b/emacs/notmuch-maildir-fcc.el
index efbb37f1..63e5514c 100644
--- a/emacs/notmuch-maildir-fcc.el
+++ b/emacs/notmuch-maildir-fcc.el
@@ -207,11 +207,11 @@ (defun notmuch-maildir-notmuch-insert-current-buffer (folder &optional create ta
 database in folder FOLDER. If CREATE is non-nil it will supply
 the --create-folder flag to create the folder if necessary. TAGS
 should be a list of tag changes to apply to the inserted message."
-  (let* ((args (append (and create (list "--create-folder"))
-		       (list (concat "--folder=" folder))
-		       tags)))
-    (apply 'notmuch-call-notmuch-process
-	   :stdin-string (buffer-string) "insert" args)))
+  (apply 'notmuch-call-notmuch-process
+	 :stdin-string (buffer-string) "insert"
+	 (append (and create (list "--create-folder"))
+		 (list (concat "--folder=" folder))
+		 tags)))
 
 (defun notmuch-maildir-fcc-with-notmuch-insert (fcc-header &optional create)
   "Store message with notmuch insert.
diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el
index 48374b38..27925669 100644
--- a/emacs/notmuch-show.el
+++ b/emacs/notmuch-show.el
@@ -1666,13 +1666,13 @@ (defun notmuch-show-get-prop (prop &optional props)
 message in either tree or show. This means that several utility
 functions in notmuch-show can be used directly by notmuch-tree as
 they just need the correct message properties."
-  (let ((props (or props
-		   (cond ((eq major-mode 'notmuch-show-mode)
-			  (notmuch-show-get-message-properties))
-			 ((eq major-mode 'notmuch-tree-mode)
-			  (notmuch-tree-get-message-properties))
-			 (t nil)))))
-    (plist-get props prop)))
+  (plist-get (or props
+		 (cond ((eq major-mode 'notmuch-show-mode)
+			(notmuch-show-get-message-properties))
+		       ((eq major-mode 'notmuch-tree-mode)
+			(notmuch-tree-get-message-properties))
+		       (t nil)))
+	     prop))
 
 (defun notmuch-show-get-message-id (&optional bare)
   "Return an id: query for the Message-Id of the current message.
diff --git a/emacs/notmuch-tag.el b/emacs/notmuch-tag.el
index c006026c..3c958dd4 100644
--- a/emacs/notmuch-tag.el
+++ b/emacs/notmuch-tag.el
@@ -406,8 +406,9 @@ (defun notmuch-tag-completions (&rest search-terms)
    "\n+" t))
 
 (defun notmuch-select-tag-with-completion (prompt &rest search-terms)
-  (let ((tag-list (apply #'notmuch-tag-completions search-terms)))
-    (completing-read prompt tag-list nil nil nil 'notmuch-select-tag-history)))
+  (completing-read prompt
+		   (apply #'notmuch-tag-completions search-terms)
+		   nil nil nil 'notmuch-select-tag-history))
 
 (defun notmuch-read-tag-changes (current-tags &optional prompt initial-input)
   "Prompt for tag changes in the minibuffer.
@@ -455,10 +456,9 @@ (defun notmuch-update-tags (tags tag-changes)
 from TAGS if present."
   (let ((result-tags (copy-sequence tags)))
     (dolist (tag-change tag-changes)
-      (let ((op (aref tag-change 0))
-	    (tag (and (not (string= tag-change ""))
+      (let ((tag (and (not (string= tag-change ""))
 		      (substring tag-change 1))))
-	(cl-case op
+	(cl-case (aref tag-change 0)
 	  (?+ (unless (member tag result-tags)
 		(push tag result-tags)))
 	  (?- (setq result-tags (delete tag result-tags)))
diff --git a/emacs/notmuch-tree.el b/emacs/notmuch-tree.el
index a06afc2d..51a43edd 100644
--- a/emacs/notmuch-tree.el
+++ b/emacs/notmuch-tree.el
@@ -401,9 +401,8 @@ (defun notmuch-tree-set-prop (prop val &optional props)
     (notmuch-tree-set-message-properties props)))
 
 (defun notmuch-tree-get-prop (prop &optional props)
-  (let ((props (or props
-		   (notmuch-tree-get-message-properties))))
-    (plist-get props prop)))
+  (plist-get (or props (notmuch-tree-get-message-properties))
+	     prop))
 
 (defun notmuch-tree-set-tags (tags)
   "Set the tags of the current message."
diff --git a/emacs/notmuch.el b/emacs/notmuch.el
index 40b730df..3436e1fc 100644
--- a/emacs/notmuch.el
+++ b/emacs/notmuch.el
@@ -521,17 +521,16 @@ (defun notmuch-search-show-thread (&optional elide-toggle)
 `notmuch-show-only-matching-messages' when displaying the
 thread."
   (interactive "P")
-  (let ((thread-id (notmuch-search-find-thread-id))
-	(subject (notmuch-search-find-subject)))
-    (if (> (length thread-id) 0)
+  (let ((thread-id (notmuch-search-find-thread-id)))
+    (if thread-id
 	(notmuch-show thread-id
 		      elide-toggle
 		      (current-buffer)
 		      notmuch-search-query-string
 		      ;; Name the buffer based on the subject.
-		      (concat "*"
-			      (truncate-string-to-width subject 30 nil nil t)
-			      "*"))
+		      (format "*%s*" (truncate-string-to-width
+				      (notmuch-search-find-subject)
+				      30 nil nil t)))
       (message "End of search results."))))
 
 (defun notmuch-tree-from-search-current-query ()
@@ -556,20 +555,21 @@ (defun notmuch-tree-from-search-thread ()
 (defun notmuch-search-reply-to-thread (&optional prompt-for-sender)
   "Begin composing a reply-all to the entire current thread in a new buffer."
   (interactive "P")
-  (let ((message-id (notmuch-search-find-thread-id)))
-    (notmuch-mua-new-reply message-id prompt-for-sender t)))
+  (notmuch-mua-new-reply (notmuch-search-find-thread-id)
+			 prompt-for-sender t))
 
 (defun notmuch-search-reply-to-thread-sender (&optional prompt-for-sender)
   "Begin composing a reply to the entire current thread in a new buffer."
   (interactive "P")
-  (let ((message-id (notmuch-search-find-thread-id)))
-    (notmuch-mua-new-reply message-id prompt-for-sender nil)))
+  (notmuch-mua-new-reply (notmuch-search-find-thread-id)
+			 prompt-for-sender nil))
 
 ;;; Tags
 
 (defun notmuch-search-set-tags (tags &optional pos)
-  (let ((new-result (plist-put (notmuch-search-get-result pos) :tags tags)))
-    (notmuch-search-update-result new-result pos)))
+  (notmuch-search-update-result
+   (plist-put (notmuch-search-get-result pos) :tags tags)
+   pos))
 
 (defun notmuch-search-get-tags (&optional pos)
   (plist-get (notmuch-search-get-result pos) :tags))
@@ -1013,10 +1013,9 @@ (defun notmuch-search (&optional query oldest-first target-thread target-line no
     (setq notmuch-search-target-thread target-thread)
     (setq notmuch-search-target-line target-line)
     (notmuch-tag-clear-cache)
-    (let ((proc (get-buffer-process (current-buffer)))
-	  (inhibit-read-only t))
-      (when proc
-	(error "notmuch search process already running for query `%s'" query))
+    (when (get-buffer-process buffer)
+      (error "notmuch search process already running for query `%s'" query))
+    (let ((inhibit-read-only t))
       (erase-buffer)
       (goto-char (point-min))
       (save-excursion
@@ -1045,13 +1044,12 @@ (defun notmuch-search-refresh-view ()
 thread. Otherwise, point will be moved to attempt to be in the
 same relative position within the new buffer."
   (interactive)
-  (let ((target-line (line-number-at-pos))
-	(oldest-first notmuch-search-oldest-first)
-	(target-thread (notmuch-search-find-thread-id 'bare))
-	(query notmuch-search-query-string))
-    ;; notmuch-search erases the current buffer.
-    (notmuch-search query oldest-first target-thread target-line t)
-    (goto-char (point-min))))
+  (notmuch-search notmuch-search-query-string
+		  notmuch-search-oldest-first
+		  (notmuch-search-find-thread-id 'bare)
+		  (line-number-at-pos)
+		  t)
+  (goto-char (point-min)))
 
 (defun notmuch-search-toggle-order ()
   "Toggle the current search order.
@@ -1160,9 +1158,9 @@ (defun notmuch-search-imenu-extract-index-name-function ()
   "Return imenu name for line at point.
 Used as `imenu-extract-index-name-function' in notmuch buffers.
 Point should be at the beginning of the line."
-  (let ((subject (notmuch-search-find-subject))
-	(author (notmuch-search-find-authors)))
-    (format "%s (%s)" subject author)))
+  (format "%s (%s)"
+	  (notmuch-search-find-subject)
+	  (notmuch-search-find-authors)))
 
 ;;; _
 
-- 
2.29.1

  parent reply	other threads:[~2021-01-10 14:04 UTC|newest]

Thread overview: 79+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-14 16:23 [PATCH 00/32] [emacs] Add outline headings and switch to lexical scope Jonas Bernoulli
2020-12-14 16:23 ` [PATCH 01/32] emacs: use setq instead of set Jonas Bernoulli
2020-12-14 16:23 ` [PATCH 02/32] emacs: sanitize dedicated widget action/notify functions Jonas Bernoulli
2020-12-14 16:23 ` [PATCH 03/32] emacs: define new notmuch-search-item widget type Jonas Bernoulli
2020-12-14 16:23 ` [PATCH 04/32] emacs: notmuch-start-notmuch: remove backward compatibility code Jonas Bernoulli
2020-12-14 16:23 ` [PATCH 05/32] emacs: notmuch-start-notmuch-error-sentinel: assert buffer is alive Jonas Bernoulli
2020-12-14 16:23 ` [PATCH 06/32] emacs: notmuch-start-notmuch-sentinel: " Jonas Bernoulli
2020-12-14 16:23 ` [PATCH 07/32] emacs: notmuch-start-notmuch: avoid storing process buffer twice Jonas Bernoulli
2020-12-14 16:23 ` [PATCH 08/32] emacs: avoid passing around some redundant information Jonas Bernoulli
2020-12-14 16:23 ` [PATCH 09/32] emacs: avoid killing process buffer when process is still alive Jonas Bernoulli
2020-12-14 16:23 ` [PATCH 10/32] emacs: make headings outline-minor-mode compatible Jonas Bernoulli
2020-12-14 16:23 ` [PATCH 11/32] emacs: use lexical-bindings in all libraries Jonas Bernoulli
2020-12-14 16:23 ` [PATCH 12/32] emacs: deal with unused lexical arguments and variables Jonas Bernoulli
2020-12-14 16:23 ` [PATCH 13/32] emacs: notmuch-tag--get-formats: silence byte-compiler Jonas Bernoulli
2020-12-14 16:23 ` [PATCH 14/32] emacs: inline notmuch-sexp-eof into only caller Jonas Bernoulli
2020-12-14 16:23 ` [PATCH 15/32] emacs: notmuch-wash-region-to-button: remove unused MSG argument Jonas Bernoulli
2020-12-14 16:23 ` [PATCH 16/32] emacs: silence compiler wrt notmuch-show-insert-part-text/plain Jonas Bernoulli
2020-12-14 16:23 ` [PATCH 17/32] emacs: define notmuch-message-queued-tag-changes as buffer-local Jonas Bernoulli
2020-12-14 16:23 ` [PATCH 18/32] emacs: notmuch-message-apply-queued-tag-changes: cosmetics Jonas Bernoulli
2020-12-14 16:23 ` [PATCH 19/32] emacs: notmuch-wash.el: require diff-mode at beginning of code Jonas Bernoulli
2020-12-14 16:23 ` [PATCH 20/32] emacs: notmuch-mua-prompt-for-sender: don't force Ido on users Jonas Bernoulli
2020-12-14 16:23 ` [PATCH 21/32] emacs: notmuch-mua.el: move all options into "Options" section Jonas Bernoulli
2020-12-14 16:23 ` [PATCH 22/32] emacs: notmuch-crypto-status-button-type: fix potential bug Jonas Bernoulli
2020-12-14 16:23 ` [PATCH 23/32] emacs: various cosmetic improvements Jonas Bernoulli
2020-12-14 16:23 ` [PATCH 24/32] emacs: various comment improvements Jonas Bernoulli
2020-12-14 16:23 ` [PATCH 25/32] emacs: various doc-string improvements Jonas Bernoulli
2020-12-14 16:23 ` [PATCH 26/32] emacs: remove variable notmuch-search-disjunctive-regexp Jonas Bernoulli
2020-12-14 16:23 ` [PATCH 27/32] emacs: define a few variables as automatically buffer-local Jonas Bernoulli
2020-12-14 16:23 ` [PATCH 28/32] emacs: notmuch-search-stash-thread-id: use notmuch-search-query-string Jonas Bernoulli
2020-12-14 16:23 ` [PATCH 29/32] emacs: reorder notmuch.el a bit Jonas Bernoulli
2020-12-14 16:23 ` [PATCH 30/32] emacs: avoid unnecessary let-bindings Jonas Bernoulli
2020-12-14 16:24 ` [PATCH 31/32] emacs: use string-empty-p Jonas Bernoulli
2020-12-14 16:24 ` [PATCH 32/32] emacs: notmuch-tree-get-match: No longer define as command Jonas Bernoulli
2020-12-27 10:14 ` [PATCH 00/32] [emacs] Add outline headings and switch to lexical scope Tomi Ollila
2020-12-28 14:08   ` Tomi Ollila
2020-12-30 17:10   ` Jonas Bernoulli
2021-01-10 14:00 ` [PATCH v2 00/36] " Jonas Bernoulli
2021-01-10 14:00   ` [PATCH v2 01/36] emacs: use setq instead of set Jonas Bernoulli
2021-01-10 14:00   ` [PATCH v2 02/36] emacs: sanitize dedicated widget action/notify functions Jonas Bernoulli
2021-01-10 14:00   ` [PATCH v2 03/36] emacs: define new notmuch-search-item widget type Jonas Bernoulli
2021-01-10 14:00   ` [PATCH v2 04/36] emacs: notmuch-start-notmuch: remove backward compatibility code Jonas Bernoulli
2021-01-10 14:00   ` [PATCH v2 05/36] emacs: notmuch-start-notmuch-error-sentinel: assert buffer is alive Jonas Bernoulli
2021-01-10 14:00   ` [PATCH v2 06/36] emacs: notmuch-start-notmuch-sentinel: " Jonas Bernoulli
2021-01-10 14:00   ` [PATCH v2 07/36] emacs: notmuch-start-notmuch: avoid storing process buffer twice Jonas Bernoulli
2021-01-10 14:00   ` [PATCH v2 08/36] emacs: avoid passing around some redundant information Jonas Bernoulli
2021-01-10 14:00   ` [PATCH v2 09/36] emacs: avoid killing process buffer when process is still alive Jonas Bernoulli
2021-01-10 14:00   ` [PATCH v2 10/36] emacs: make headings outline-minor-mode compatible Jonas Bernoulli
2021-01-10 14:00   ` [PATCH v2 11/36] emacs: use lexical-bindings in all libraries Jonas Bernoulli
2021-01-10 14:00   ` [PATCH v2 12/36] emacs: deal with unused lexical arguments and variables Jonas Bernoulli
2021-01-10 14:00   ` [PATCH v2 13/36] emacs: notmuch-tag--get-formats: silence byte-compiler Jonas Bernoulli
2021-01-10 14:00   ` [PATCH v2 14/36] emacs: inline notmuch-sexp-eof into only caller Jonas Bernoulli
2021-01-10 14:00   ` [PATCH v2 15/36] emacs: notmuch-wash-region-to-button: remove unused MSG argument Jonas Bernoulli
2021-01-10 14:00   ` [PATCH v2 16/36] emacs: silence compiler wrt notmuch-show-insert-part-text/plain Jonas Bernoulli
2021-01-10 14:00   ` [PATCH v2 17/36] emacs: define notmuch-message-queued-tag-changes as buffer-local Jonas Bernoulli
2021-01-10 14:00   ` [PATCH v2 18/36] emacs: notmuch-message-apply-queued-tag-changes: cosmetics Jonas Bernoulli
2021-01-10 14:00   ` [PATCH v2 19/36] emacs: notmuch-wash.el: require diff-mode at beginning of code Jonas Bernoulli
2021-01-10 14:00   ` [PATCH v2 20/36] emacs: notmuch-mua-prompt-for-sender: don't force Ido on users Jonas Bernoulli
2021-01-10 14:00   ` [PATCH v2 21/36] emacs: notmuch-mua.el: move all options into "Options" section Jonas Bernoulli
2021-01-10 14:00   ` [PATCH v2 22/36] emacs: notmuch-crypto-status-button-type: fix potential bug Jonas Bernoulli
2021-01-10 14:00   ` [PATCH v2 23/36] emacs: various cosmetic improvements Jonas Bernoulli
2021-01-13 17:37     ` [PATCH v3 " Jonas Bernoulli
2021-01-10 14:01   ` [PATCH v2 24/36] emacs: various comment improvements Jonas Bernoulli
2021-01-10 14:01   ` [PATCH v2 25/36] emacs: various doc-string improvements Jonas Bernoulli
2021-01-10 14:01   ` [PATCH v2 26/36] emacs: remove variable notmuch-search-disjunctive-regexp Jonas Bernoulli
2021-01-10 14:01   ` [PATCH v2 27/36] emacs: define a few variables as automatically buffer-local Jonas Bernoulli
2021-01-10 14:01   ` [PATCH v2 28/36] emacs: notmuch-search-stash-thread-id: use notmuch-search-query-string Jonas Bernoulli
2021-01-10 14:01   ` [PATCH v2 29/36] emacs: reorder notmuch.el a bit Jonas Bernoulli
2021-01-10 14:01   ` Jonas Bernoulli [this message]
2021-01-10 14:01   ` [PATCH v2 31/36] emacs: improve how cl-lib and pcase are required Jonas Bernoulli
2021-01-10 14:01   ` [PATCH v2 32/36] emacs: make subr-x available in all libraries Jonas Bernoulli
2021-01-10 14:01   ` [PATCH v2 33/36] emacs: use string-empty-p Jonas Bernoulli
2021-01-10 14:01   ` [PATCH v2 34/36] emacs: notmuch-tree-get-match: No longer define as command Jonas Bernoulli
2021-01-10 14:01   ` [PATCH v2 35/36] emacs: allow opting out of notmuch's address completion Jonas Bernoulli
2021-01-10 14:01   ` [PATCH v2 36/36] emacs: notmuch-address-expand-name: use the actual initial-input Jonas Bernoulli
2021-01-15 11:28     ` David Bremner
2021-01-13  9:13   ` [PATCH v2 00/36] [emacs] Add outline headings and switch to lexical scope Tomi Ollila
2021-01-13 12:11   ` David Bremner
2021-01-13 13:02     ` Tomi Ollila
2021-01-13 17:41     ` Jonas Bernoulli

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://notmuchmail.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210110140112.25930-31-jonas@bernoul.li \
    --to=jonas@bernoul.li \
    --cc=notmuch@notmuchmail.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).