From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp1 ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms11 with LMTPS id 6ESqD0KS11/idQAA0tVLHw (envelope-from ) for ; Mon, 14 Dec 2020 16:26:42 +0000 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp1 with LMTPS id KFxwC0KS119iIAAAbx9fmQ (envelope-from ) for ; Mon, 14 Dec 2020 16:26:42 +0000 Received: from mail.notmuchmail.org (nmbug.tethera.net [144.217.243.247]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (2048 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id A91F89401BF for ; Mon, 14 Dec 2020 16:26:41 +0000 (UTC) Received: from nmbug.tethera.net (localhost [127.0.0.1]) by mail.notmuchmail.org (Postfix) with ESMTP id 2FDF729D14; Mon, 14 Dec 2020 11:25:12 -0500 (EST) Received: from mail.hostpark.net (mail.hostpark.net [212.243.197.30]) by mail.notmuchmail.org (Postfix) with ESMTPS id 5A74A28C03 for ; Mon, 14 Dec 2020 11:24:08 -0500 (EST) Received: from localhost (localhost [127.0.0.1]) by mail.hostpark.net (Postfix) with ESMTP id 0B2A41665A for ; Mon, 14 Dec 2020 17:24:04 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=bernoul.li; h= content-transfer-encoding:mime-version:references:in-reply-to :x-mailer:message-id:date:date:subject:subject:from:from :received:received; s=sel2011a; t=1607963043; bh=t0plrztYvtt417j 6Rgt63045OonjwMeoSiHYMN6bkfA=; b=TTCCNqs+z0/GyJo4jrb/g72La2zp/Uc uh5kofKO2BNreOc7HMQeEUaqBOuxx7V/sr6xs+E/jmhyIrp9+rvqxa6wd+BmPOuE EoVQj9rr0T2blcKmLZeIUcitjwq4fjFwdsUFG1imfkARoS7irasYKQ6gROMbEs/M hhzz7e4TpAT8= X-Virus-Scanned: by Hostpark/NetZone Mailprotection at hostpark.net Received: from mail.hostpark.net ([127.0.0.1]) by localhost (mail0.hostpark.net [127.0.0.1]) (amavisd-new, port 10224) with ESMTP id 7ZWrkhltFHka for ; Mon, 14 Dec 2020 17:24:03 +0100 (CET) Received: from customer (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mail.hostpark.net (Postfix) with ESMTPSA id BD4651666F for ; Mon, 14 Dec 2020 17:24:03 +0100 (CET) From: Jonas Bernoulli To: notmuch@notmuchmail.org Subject: [PATCH 30/32] emacs: avoid unnecessary let-bindings Date: Mon, 14 Dec 2020 17:23:59 +0100 Message-Id: <20201214162401.19569-31-jonas@bernoul.li> X-Mailer: git-send-email 2.29.1 In-Reply-To: <20201214162401.19569-1-jonas@bernoul.li> References: <20201214162401.19569-1-jonas@bernoul.li> MIME-Version: 1.0 Message-ID-Hash: MOREAYQ7LU6XJODQIHQ63MMW4GAEG7CO X-Message-ID-Hash: MOREAYQ7LU6XJODQIHQ63MMW4GAEG7CO X-MailFrom: jonas@bernoul.li X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-notmuch.notmuchmail.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header X-Mailman-Version: 3.2.1 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Help: List-Post: List-Subscribe: List-Unsubscribe: Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Migadu-Flow: FLOW_IN X-Migadu-Spam-Score: 1.42 Authentication-Results: aspmx1.migadu.com; dkim=fail (body hash did not verify) header.d=bernoul.li header.s=sel2011a header.b=TTCCNqs+; dmarc=none; spf=pass (aspmx1.migadu.com: domain of notmuch-bounces@notmuchmail.org designates 144.217.243.247 as permitted sender) smtp.mailfrom=notmuch-bounces@notmuchmail.org X-Migadu-Queue-Id: A91F89401BF X-Spam-Score: 1.42 X-Migadu-Scanner: scn0.migadu.com X-TUID: fBFP1utjPh0d 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 0000863d..8a5c5640 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 24b930bf..6553893b 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)) @@ -1017,10 +1017,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 @@ -1049,13 +1048,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. @@ -1164,9 +1162,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