]> git.notmuchmail.org Git - notmuch/blobdiff - emacs/notmuch.el
emacs: move tag format validation to `notmuch-tag' function
[notmuch] / emacs / notmuch.el
index 72f78edcbcd401e5a729b1586753c143734ce52d..19206db5032507bddccaa010a2274a21aaed8e96 100644 (file)
@@ -467,19 +467,13 @@ Complete list of currently available key bindings:
   "Display the currently selected thread."
   (interactive "P")
   (let ((thread-id (notmuch-search-find-thread-id))
-       (subject (notmuch-search-find-subject)))
+       (subject (notmuch-prettify-subject (notmuch-search-find-subject))))
     (if (> (length thread-id) 0)
        (notmuch-show thread-id
                      (current-buffer)
                      notmuch-search-query-string
-                     ;; name the buffer based on notmuch-search-find-subject
-                     (if (string-match "^[ \t]*$" subject)
-                         "[No Subject]"
-                       (truncate-string-to-width
-                        (concat "*"
-                                (truncate-string-to-width subject 32 nil nil t)
-                                "*")
-                        32 nil nil t))
+                     ;; Name the buffer based on the subject.
+                     (concat "*" (truncate-string-to-width subject 30 nil nil t) "*")
                      crypto-switch)
       (message "End of search results."))))
 
@@ -522,6 +516,12 @@ Note: Other code should always use this function alter tags of
 messages instead of running (notmuch-call-notmuch-process \"tag\" ..)
 directly, so that hooks specified in notmuch-before-tag-hook and
 notmuch-after-tag-hook will be run."
+  ;; Perform some validation
+  (when (null tags) (error "No tags given"))
+  (mapc (lambda (tag)
+         (unless (string-match-p "^[-+][-+_.[:word:]]+$" tag)
+           (error "Tag must be of the form `+this_tag' or `-that_tag'")))
+       tags)
   (run-hooks 'notmuch-before-tag-hook)
   (apply 'notmuch-call-notmuch-process
         (append (list "tag") tags (list "--" query)))
@@ -673,17 +673,16 @@ This function advances the next thread when finished."
                  (goto-char (point-max))
                  (if (eq status 'signal)
                      (insert "Incomplete search results (search process was killed).\n"))
-                 (if (eq status 'exit)
-                     (progn
-                       (if notmuch-search-process-filter-data
-                           (insert (concat "Error: Unexpected output from notmuch search:\n" notmuch-search-process-filter-data)))
-                       (insert "End of search results.")
-                       (unless (= exit-status 0)
-                         (insert (format " (process returned %d)" exit-status)))
-                       (insert "\n")
-                       (if (and atbob
-                                (not (string= notmuch-search-target-thread "found")))
-                           (set 'never-found-target-thread t))))))
+                 (when (eq status 'exit)
+                   (if notmuch-search-process-filter-data
+                       (insert (concat "Error: Unexpected output from notmuch search:\n" notmuch-search-process-filter-data)))
+                   (insert "End of search results.")
+                   (unless (= exit-status 0)
+                     (insert (format " (process returned %d)" exit-status)))
+                   (insert "\n")
+                   (if (and atbob
+                            (not (string= notmuch-search-target-thread "found")))
+                       (set 'never-found-target-thread t)))))
              (when (and never-found-target-thread
                       notmuch-search-target-line)
                  (goto-char (point-min))
@@ -856,15 +855,15 @@ non-authors is found, assume that all of the authors match."
                      (if (/= (match-beginning 1) line)
                          (insert (concat "Error: Unexpected output from notmuch search:\n" (substring string line (match-beginning 1)) "\n")))
                      (let ((beg (point)))
-                       (notmuch-search-show-result date count authors subject tags)
+                       (notmuch-search-show-result date count authors
+                                                   (notmuch-prettify-subject subject) tags)
                        (notmuch-search-color-line beg (point) tag-list)
                        (put-text-property beg (point) 'notmuch-search-thread-id thread-id)
                        (put-text-property beg (point) 'notmuch-search-authors authors)
                        (put-text-property beg (point) 'notmuch-search-subject subject)
-                       (if (string= thread-id notmuch-search-target-thread)
-                           (progn
-                             (set 'found-target beg)
-                             (set 'notmuch-search-target-thread "found"))))
+                       (when (string= thread-id notmuch-search-target-thread)
+                         (set 'found-target beg)
+                         (set 'notmuch-search-target-thread "found")))
                      (set 'line (match-end 0)))
                  (set 'more nil)
                  (while (and (< line (length string)) (= (elt string line) ?\n))
@@ -890,12 +889,6 @@ characters as well as `_.+-'.
   (interactive (notmuch-select-tags-with-completion
                "Operations (+add -drop): notmuch tag "
                '("+" "-")))
-  ;; Perform some validation
-  (when (null actions) (error "No operations given"))
-  (mapc (lambda (action)
-         (unless (string-match-p "^[-+][-+_.[:word:]]+$" action)
-           (error "Action must be of the form `+this_tag' or `-that_tag'")))
-       actions)
   (apply 'notmuch-tag notmuch-search-query-string actions))
 
 (defun notmuch-search-buffer-title (query)