mirror of
https://git.notmuchmail.org/git/notmuch
synced 2024-12-22 17:34:54 +01:00
emacs: Use 'and' instead of 'when' when the return value matters
Also do so for some 'if' forms that lack an ELSE part. Even go as far as using 'and' and 'not' instead of 'unless'.
This commit is contained in:
parent
18d289c863
commit
dfb1b8eb89
11 changed files with 114 additions and 113 deletions
|
@ -107,12 +107,12 @@ not need to be wrapped, move point to the next line and return t."
|
|||
If the line should not be broken, return nil; point remains on the
|
||||
line."
|
||||
(move-to-column fill-column)
|
||||
(if (and (re-search-forward "[^ ]" (line-end-position) 1)
|
||||
(> (current-column) fill-column))
|
||||
;; This line is too long. Can we break it?
|
||||
(or (coolj-find-break-backward prefix)
|
||||
(progn (move-to-column fill-column)
|
||||
(coolj-find-break-forward)))))
|
||||
(and (re-search-forward "[^ ]" (line-end-position) 1)
|
||||
(> (current-column) fill-column)
|
||||
;; This line is too long. Can we break it?
|
||||
(or (coolj-find-break-backward prefix)
|
||||
(progn (move-to-column fill-column)
|
||||
(coolj-find-break-forward)))))
|
||||
|
||||
(defun coolj-find-break-backward (prefix)
|
||||
"Move point backward to the first available breakpoint and return t.
|
||||
|
|
|
@ -252,20 +252,20 @@ external commands."
|
|||
(defun notmuch-address-locate-command (command)
|
||||
"Return non-nil if `command' is an executable either on
|
||||
`exec-path' or an absolute pathname."
|
||||
(when (stringp command)
|
||||
(if (and (file-name-absolute-p command)
|
||||
(file-executable-p command))
|
||||
command
|
||||
(setq command (file-name-nondirectory command))
|
||||
(catch 'found-command
|
||||
(let (bin)
|
||||
(dolist (dir exec-path)
|
||||
(setq bin (expand-file-name command dir))
|
||||
(when (or (and (file-executable-p bin)
|
||||
(not (file-directory-p bin)))
|
||||
(and (file-executable-p (setq bin (concat bin ".exe")))
|
||||
(not (file-directory-p bin))))
|
||||
(throw 'found-command bin))))))))
|
||||
(and (stringp command)
|
||||
(if (and (file-name-absolute-p command)
|
||||
(file-executable-p command))
|
||||
command
|
||||
(setq command (file-name-nondirectory command))
|
||||
(catch 'found-command
|
||||
(let (bin)
|
||||
(dolist (dir exec-path)
|
||||
(setq bin (expand-file-name command dir))
|
||||
(when (or (and (file-executable-p bin)
|
||||
(not (file-directory-p bin)))
|
||||
(and (file-executable-p (setq bin (concat bin ".exe")))
|
||||
(not (file-directory-p bin))))
|
||||
(throw 'found-command bin))))))))
|
||||
|
||||
(defun notmuch-address-harvest-addr (result)
|
||||
(let ((name-addr (plist-get result :name-addr)))
|
||||
|
@ -304,18 +304,20 @@ asynchronously unless SYNCHRONOUS is t. In case of asynchronous
|
|||
execution, CALLBACK is called when harvesting finishes."
|
||||
(let* ((sent (eq (car notmuch-address-internal-completion) 'sent))
|
||||
(config-query (cadr notmuch-address-internal-completion))
|
||||
(prefix-query (when addr-prefix
|
||||
(format "%s:%s*" (if sent "to" "from") addr-prefix)))
|
||||
(prefix-query (and addr-prefix
|
||||
(format "%s:%s*"
|
||||
(if sent "to" "from")
|
||||
addr-prefix)))
|
||||
(from-or-to-me-query
|
||||
(mapconcat (lambda (x)
|
||||
(concat (if sent "from:" "to:") x))
|
||||
(notmuch-user-emails) " or "))
|
||||
(query (if (or prefix-query config-query)
|
||||
(concat (format "(%s)" from-or-to-me-query)
|
||||
(when prefix-query
|
||||
(format " and (%s)" prefix-query))
|
||||
(when config-query
|
||||
(format " and (%s)" config-query)))
|
||||
(and prefix-query
|
||||
(format " and (%s)" prefix-query))
|
||||
(and config-query
|
||||
(format " and (%s)" config-query)))
|
||||
from-or-to-me-query))
|
||||
(args `("address" "--format=sexp" "--format-version=4"
|
||||
,(if sent "--output=recipients" "--output=sender")
|
||||
|
@ -354,21 +356,21 @@ execution, CALLBACK is called when harvesting finishes."
|
|||
|
||||
Returns nil if the save file does not exist, or it does not seem
|
||||
to be a saved address hash."
|
||||
(when notmuch-address-save-filename
|
||||
(condition-case nil
|
||||
(with-temp-buffer
|
||||
(insert-file-contents notmuch-address-save-filename)
|
||||
(let ((name (read (current-buffer)))
|
||||
(plist (read (current-buffer))))
|
||||
;; We do two simple sanity checks on the loaded file. We just
|
||||
;; check a version is specified, not that it is the current
|
||||
;; version, as we are allowed to over-write and a save-file with
|
||||
;; an older version.
|
||||
(when (and (string= name "notmuch-address-hash")
|
||||
(plist-get plist :version))
|
||||
plist)))
|
||||
;; The error case catches any of the reads failing.
|
||||
(error nil))))
|
||||
(and notmuch-address-save-filename
|
||||
(condition-case nil
|
||||
(with-temp-buffer
|
||||
(insert-file-contents notmuch-address-save-filename)
|
||||
(let ((name (read (current-buffer)))
|
||||
(plist (read (current-buffer))))
|
||||
;; We do two simple sanity checks on the loaded file.
|
||||
;; We just check a version is specified, not that
|
||||
;; it is the current version, as we are allowed to
|
||||
;; over-write and a save-file with an older version.
|
||||
(and (string= name "notmuch-address-hash")
|
||||
(plist-get plist :version)
|
||||
plist)))
|
||||
;; The error case catches any of the reads failing.
|
||||
(error nil))))
|
||||
|
||||
(defun notmuch-address--load-address-hash ()
|
||||
"Read the saved address hash and set the corresponding variables."
|
||||
|
|
|
@ -253,7 +253,7 @@ corresponding key when the status button is pressed."
|
|||
"Decryption error")
|
||||
(t
|
||||
(concat "Unknown encryption status"
|
||||
(if status (concat ": " status))))))
|
||||
(and status (concat ": " status))))))
|
||||
" ]")
|
||||
:type 'notmuch-crypto-status-button-type
|
||||
'face 'notmuch-crypto-decryption
|
||||
|
|
|
@ -263,7 +263,7 @@ applied to newly inserted messages)."
|
|||
;; If the resumed message was a draft then set the draft
|
||||
;; message-id so that we can delete the current saved draft if the
|
||||
;; message is resaved or sent.
|
||||
(setq notmuch-draft-id (when draft id)))))
|
||||
(setq notmuch-draft-id (and draft id)))))
|
||||
|
||||
|
||||
(add-hook 'message-send-hook 'notmuch-draft--mark-deleted)
|
||||
|
|
|
@ -608,7 +608,7 @@ the given type."
|
|||
(set-buffer-multibyte nil))
|
||||
(let ((args `("show" "--format=raw"
|
||||
,(format "--part=%s" (plist-get part :id))
|
||||
,@(when process-crypto '("--decrypt=true"))
|
||||
,@(and process-crypto '("--decrypt=true"))
|
||||
,(notmuch-id-to-query (plist-get msg :id))))
|
||||
(coding-system-for-read
|
||||
(if binaryp 'no-conversion
|
||||
|
@ -781,8 +781,8 @@ signaled error. This function does not return."
|
|||
(insert extra)
|
||||
(unless (bolp)
|
||||
(newline)))))
|
||||
(error "%s" (concat msg (when extra
|
||||
" (see *Notmuch errors* for more details)"))))
|
||||
(error "%s"
|
||||
(concat msg (and extra " (see *Notmuch errors* for more details)"))))
|
||||
|
||||
(defun notmuch-check-async-exit-status (proc msg &optional command err)
|
||||
"If PROC exited abnormally, pop up an error buffer and signal an error.
|
||||
|
@ -836,10 +836,8 @@ You may need to restart Emacs or upgrade your notmuch package."))
|
|||
(if (integerp exit-status)
|
||||
(format "exit status: %s\n" exit-status)
|
||||
(format "exit signal: %s\n" exit-status))
|
||||
(when err
|
||||
(concat "stderr:\n" err))
|
||||
(when output
|
||||
(concat "stdout:\n" output)))))
|
||||
(and err (concat "stderr:\n" err))
|
||||
(and output (concat "stdout:\n" output)))))
|
||||
(if err
|
||||
;; We have an error message straight from the CLI.
|
||||
(notmuch-logged-error
|
||||
|
@ -968,8 +966,8 @@ status."
|
|||
(let* ((err-file (process-get proc 'err-file))
|
||||
(err-buffer (or (process-get proc 'err-buffer)
|
||||
(find-file-noselect err-file)))
|
||||
(err (when (not (zerop (buffer-size err-buffer)))
|
||||
(with-current-buffer err-buffer (buffer-string))))
|
||||
(err (and (not (zerop (buffer-size err-buffer)))
|
||||
(with-current-buffer err-buffer (buffer-string))))
|
||||
(sub-sentinel (process-get proc 'sub-sentinel))
|
||||
(real-command (process-get proc 'real-command)))
|
||||
(condition-case err
|
||||
|
@ -987,16 +985,17 @@ status."
|
|||
;; If that didn't signal an error, then any error output was
|
||||
;; really warning output. Show warnings, if any.
|
||||
(let ((warnings
|
||||
(when err
|
||||
(with-current-buffer err-buffer
|
||||
(goto-char (point-min))
|
||||
(end-of-line)
|
||||
;; Show first line; stuff remaining lines in the
|
||||
;; errors buffer.
|
||||
(let ((l1 (buffer-substring (point-min) (point))))
|
||||
(skip-chars-forward "\n")
|
||||
(cons l1 (unless (eobp)
|
||||
(buffer-substring (point) (point-max)))))))))
|
||||
(and err
|
||||
(with-current-buffer err-buffer
|
||||
(goto-char (point-min))
|
||||
(end-of-line)
|
||||
;; Show first line; stuff remaining lines in the
|
||||
;; errors buffer.
|
||||
(let ((l1 (buffer-substring (point-min) (point))))
|
||||
(skip-chars-forward "\n")
|
||||
(cons l1 (and (not (eobp))
|
||||
(buffer-substring (point)
|
||||
(point-max)))))))))
|
||||
(when warnings
|
||||
(notmuch-logged-error (car warnings) (cdr warnings)))))
|
||||
(error
|
||||
|
|
|
@ -215,7 +215,7 @@ This inserts the current buffer as a message into the notmuch
|
|||
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 (when create (list "--create-folder"))
|
||||
(let* ((args (append (and create (list "--create-folder"))
|
||||
(list (concat "--folder=" folder))
|
||||
tags)))
|
||||
(apply 'notmuch-call-notmuch-process
|
||||
|
@ -315,7 +315,7 @@ if successful, nil if not."
|
|||
(defun notmuch-maildir-fcc-move-tmp-to-cur (destdir msg-id &optional mark-seen)
|
||||
(add-name-to-file
|
||||
(concat destdir "/tmp/" msg-id)
|
||||
(concat destdir "/cur/" msg-id ":2," (when mark-seen "S"))))
|
||||
(concat destdir "/cur/" msg-id ":2," (and mark-seen "S"))))
|
||||
|
||||
(defun notmuch-maildir-fcc-file-fcc (fcc-header)
|
||||
"Write the message to the file specified by FCC-HEADER.
|
||||
|
|
|
@ -460,8 +460,8 @@ If PROMPT-FOR-SENDER is non-nil, the user will be prompted for
|
|||
the From: address first."
|
||||
(interactive "P")
|
||||
(let ((other-headers
|
||||
(when (or prompt-for-sender notmuch-always-prompt-for-sender)
|
||||
(list (cons 'From (notmuch-mua-prompt-for-sender))))))
|
||||
(and (or prompt-for-sender notmuch-always-prompt-for-sender)
|
||||
(list (cons 'From (notmuch-mua-prompt-for-sender))))))
|
||||
(notmuch-mua-mail nil nil other-headers nil (notmuch-mua-get-switch-function))))
|
||||
|
||||
(defun notmuch-mua-new-forward-messages (messages &optional prompt-for-sender)
|
||||
|
@ -470,8 +470,8 @@ the From: address first."
|
|||
If PROMPT-FOR-SENDER is non-nil, the user will be prompteed for
|
||||
the From: address."
|
||||
(let* ((other-headers
|
||||
(when (or prompt-for-sender notmuch-always-prompt-for-sender)
|
||||
(list (cons 'From (notmuch-mua-prompt-for-sender)))))
|
||||
(and (or prompt-for-sender notmuch-always-prompt-for-sender)
|
||||
(list (cons 'From (notmuch-mua-prompt-for-sender)))))
|
||||
;; Comes from the first message and is applied later.
|
||||
forward-subject
|
||||
;; List of accumulated message-references of forwarded messages.
|
||||
|
@ -542,9 +542,8 @@ will be addressed to all recipients of the source message."
|
|||
;; primary selection was previously in a non-emacs window but not if
|
||||
;; it was in an emacs window. To avoid the problem in the latter case
|
||||
;; we deactivate mark.
|
||||
(let ((sender
|
||||
(when prompt-for-sender
|
||||
(notmuch-mua-prompt-for-sender)))
|
||||
(let ((sender (and prompt-for-sender
|
||||
(notmuch-mua-prompt-for-sender)))
|
||||
(select-active-regions nil))
|
||||
(notmuch-mua-reply query-string sender reply-all)
|
||||
(deactivate-mark)))
|
||||
|
|
|
@ -506,10 +506,10 @@ message at DEPTH in the current thread."
|
|||
(defun notmuch-show-insert-part-header (nth content-type declared-type
|
||||
&optional name comment)
|
||||
(let ((button)
|
||||
(base-label (concat (when name (concat name ": "))
|
||||
(base-label (concat (and name (concat name ": "))
|
||||
declared-type
|
||||
(unless (string-equal declared-type content-type)
|
||||
(concat " (as " content-type ")"))
|
||||
(and (not (string-equal declared-type content-type))
|
||||
(concat " (as " content-type ")"))
|
||||
comment)))
|
||||
(setq button
|
||||
(insert-button
|
||||
|
@ -787,18 +787,15 @@ will return nil if the CID is unknown or cannot be retrieved."
|
|||
(defun notmuch-show-get-mime-type-of-application/octet-stream (part)
|
||||
;; If we can deduce a MIME type from the filename of the attachment,
|
||||
;; we return that.
|
||||
(if (plist-get part :filename)
|
||||
(let ((extension (file-name-extension (plist-get part :filename)))
|
||||
mime-type)
|
||||
(if extension
|
||||
(progn
|
||||
(mailcap-parse-mimetypes)
|
||||
(setq mime-type (mailcap-extension-to-mime extension))
|
||||
(if (and mime-type
|
||||
(not (string-equal mime-type "application/octet-stream")))
|
||||
mime-type
|
||||
nil))
|
||||
nil))))
|
||||
(and (plist-get part :filename)
|
||||
(let ((extension (file-name-extension (plist-get part :filename))))
|
||||
(and extension
|
||||
(progn
|
||||
(mailcap-parse-mimetypes)
|
||||
(let ((mime-type (mailcap-extension-to-mime extension)))
|
||||
(and mime-type
|
||||
(not (string-equal mime-type "application/octet-stream"))
|
||||
mime-type)))))))
|
||||
|
||||
(defun notmuch-show-insert-part-text/html (msg part content-type nth depth button)
|
||||
(if (eq mm-text-html-renderer 'shr)
|
||||
|
@ -997,9 +994,10 @@ is t, hide the part initially and show the button."
|
|||
(beg (point))
|
||||
;; This default header-p function omits the part button for
|
||||
;; the first (or only) part if this is text/plain.
|
||||
(button (when (funcall notmuch-show-insert-header-p-function part hide)
|
||||
(notmuch-show-insert-part-header nth mime-type content-type
|
||||
(plist-get part :filename))))
|
||||
(button (and (funcall notmuch-show-insert-header-p-function part hide)
|
||||
(notmuch-show-insert-part-header
|
||||
nth mime-type content-type
|
||||
(plist-get part :filename))))
|
||||
;; Hide the part initially if HIDE is t, or if it is too long
|
||||
;; and we have a button to allow toggling.
|
||||
(show-part (not (or (equal hide t)
|
||||
|
@ -1054,9 +1052,8 @@ is t, hide the part initially and show the button."
|
|||
(bare-subject (notmuch-show-strip-re (plist-get headers :Subject))))
|
||||
(setq message-start (point-marker))
|
||||
(notmuch-show-insert-headerline headers
|
||||
(or (if notmuch-show-relative-dates
|
||||
(plist-get msg :date_relative)
|
||||
nil)
|
||||
(or (and notmuch-show-relative-dates
|
||||
(plist-get msg :date_relative))
|
||||
(plist-get headers :Date))
|
||||
(plist-get msg :tags) depth)
|
||||
(setq content-start (point-marker))
|
||||
|
@ -1303,8 +1300,8 @@ first relevant message.
|
|||
|
||||
If no messages match the query return NIL."
|
||||
(let* ((cli-args (cons "--exclude=false"
|
||||
(when notmuch-show-elide-non-matching-messages
|
||||
(list "--entire-thread=false"))))
|
||||
(and notmuch-show-elide-non-matching-messages
|
||||
(list "--entire-thread=false"))))
|
||||
(queries (notmuch-show--build-queries
|
||||
notmuch-show-thread-id notmuch-show-query-context))
|
||||
(forest nil)
|
||||
|
@ -2412,7 +2409,7 @@ MIME-TYPE is given then set the handle's mime-type to MIME-TYPE."
|
|||
(buf (notmuch-show-generate-part-buffer msg part))
|
||||
(computed-type (or mime-type (plist-get part :computed-type)))
|
||||
(filename (plist-get part :filename))
|
||||
(disposition (if filename `(attachment (filename . ,filename)))))
|
||||
(disposition (and filename `(attachment (filename . ,filename)))))
|
||||
(mm-make-handle buf (list computed-type) nil nil disposition)))
|
||||
|
||||
(defun notmuch-show-apply-to-current-part-handle (fn &optional mime-type)
|
||||
|
|
|
@ -1020,8 +1020,8 @@ the same as for the function notmuch-tree."
|
|||
(erase-buffer)
|
||||
(goto-char (point-min))
|
||||
(let* ((search-args (concat basic-query
|
||||
(if query-context
|
||||
(concat " and (" query-context ")"))))
|
||||
(and query-context
|
||||
(concat " and (" query-context ")"))))
|
||||
(message-arg (if unthreaded "--unthreaded" "--entire-thread")))
|
||||
(if (equal (car (process-lines notmuch-command "count" search-args)) "0")
|
||||
(setq search-args basic-query))
|
||||
|
|
|
@ -370,10 +370,10 @@ filename, before trimming any trailing . and - characters."
|
|||
|
||||
Return the patch sequence number N from the last \"[PATCH N/M]\"
|
||||
style prefix in SUBJECT, or nil if such a prefix can't be found."
|
||||
(when (string-match
|
||||
"^ *\\(\\[[^]]*\\] *\\)*\\[[^]]*?\\([0-9]+\\)/[0-9]+[^]]*\\].*"
|
||||
subject)
|
||||
(string-to-number (substring subject (match-beginning 2) (match-end 2)))))
|
||||
(and (string-match
|
||||
"^ *\\(\\[[^]]*\\] *\\)*\\[[^]]*?\\([0-9]+\\)/[0-9]+[^]]*\\].*"
|
||||
subject)
|
||||
(string-to-number (substring subject (match-beginning 2) (match-end 2)))))
|
||||
|
||||
(defun notmuch-wash-subject-to-patch-filename (subject)
|
||||
"Convert a patch mail SUBJECT into a filename.
|
||||
|
|
|
@ -264,7 +264,8 @@ there will be called at other points of notmuch execution."
|
|||
(goto-char (point-max))
|
||||
(forward-line -2)
|
||||
(let ((beg (notmuch-search-result-beginning)))
|
||||
(when beg (goto-char beg))))
|
||||
(when beg
|
||||
(goto-char beg))))
|
||||
|
||||
(defun notmuch-search-first-thread ()
|
||||
"Select the first thread in the search results."
|
||||
|
@ -406,11 +407,12 @@ If there is no thread at POS (or point), returns nil."
|
|||
"Return the point at the beginning of the thread at POS (or point).
|
||||
|
||||
If there is no thread at POS (or point), returns nil."
|
||||
(when (notmuch-search-get-result pos)
|
||||
;; We pass 1+point because previous-single-property-change starts
|
||||
;; searching one before the position we give it.
|
||||
(previous-single-property-change (1+ (or pos (point)))
|
||||
'notmuch-search-result nil (point-min))))
|
||||
(and (notmuch-search-get-result pos)
|
||||
;; We pass 1+point because previous-single-property-change starts
|
||||
;; searching one before the position we give it.
|
||||
(previous-single-property-change (1+ (or pos (point)))
|
||||
'notmuch-search-result nil
|
||||
(point-min))))
|
||||
|
||||
(defun notmuch-search-result-end (&optional pos)
|
||||
"Return the point at the end of the thread at POS (or point).
|
||||
|
@ -418,9 +420,10 @@ If there is no thread at POS (or point), returns nil."
|
|||
The returned point will be just after the newline character that
|
||||
ends the result line. If there is no thread at POS (or point),
|
||||
returns nil."
|
||||
(when (notmuch-search-get-result pos)
|
||||
(next-single-property-change (or pos (point)) 'notmuch-search-result
|
||||
nil (point-max))))
|
||||
(and (notmuch-search-get-result pos)
|
||||
(next-single-property-change (or pos (point))
|
||||
'notmuch-search-result nil
|
||||
(point-max))))
|
||||
|
||||
(defun notmuch-search-foreach-result (beg end fn)
|
||||
"Invoke FN for each result between BEG and END.
|
||||
|
@ -461,7 +464,8 @@ BEG."
|
|||
|
||||
If BARE is set then do not prefix with \"thread:\"."
|
||||
(let ((thread (plist-get (notmuch-search-get-result) :thread)))
|
||||
(when thread (concat (unless bare "thread:") thread))))
|
||||
(when thread
|
||||
(concat (and (not bare) "thread:") thread))))
|
||||
|
||||
(defun notmuch-search-find-stable-query ()
|
||||
"Return the stable queries for the current thread.
|
||||
|
@ -482,8 +486,8 @@ no messages in the region then return nil."
|
|||
(push (car queries) query-list))
|
||||
(when (and all (cadr queries))
|
||||
(push (cadr queries) query-list)))
|
||||
(when query-list
|
||||
(concat "(" (mapconcat 'identity query-list ") or (") ")"))))
|
||||
(and query-list
|
||||
(concat "(" (mapconcat 'identity query-list ") or (") ")"))))
|
||||
|
||||
(defun notmuch-search-find-authors ()
|
||||
"Return the authors for the current thread."
|
||||
|
|
Loading…
Reference in a new issue