mu4e: update label handling
- Fix typos - Sync up with C++ - Fix cl-pushnew usage
This commit is contained in:
@ -30,13 +30,13 @@
|
|||||||
(require 'mu4e-helpers)
|
(require 'mu4e-helpers)
|
||||||
|
|
||||||
(defconst mu4e-label-regex
|
(defconst mu4e-label-regex
|
||||||
"[^\"',+/\\`[:cntrl:][:blank:]-][^\"'$,/\\`[:cntrl:][:blank:]]+"
|
(rx (not (any ?- ?+ ?\" ?' ?$ ?, ?/ ?\\ ?` cntrl blank))
|
||||||
|
(* (not (any ?\" ?' ?$ ?, ?/ ?\\ ?` cntrl blank))))
|
||||||
"Unanchored regular expression matching a valid label.
|
"Unanchored regular expression matching a valid label.
|
||||||
|
|
||||||
Any character is allowed that is not a control-character, a
|
Any character is allowed that is not a control-character, a
|
||||||
blank, or a number of special characters. Additionally, the first
|
blank, or a number of special characters. Additionally, the first
|
||||||
character cannot be + or - either.")
|
character cannot be + or - either.")
|
||||||
;; sadly, the 'rx' macro is not expressive enough, pre-emacs30
|
|
||||||
|
|
||||||
(defun mu4e-label-validate (str)
|
(defun mu4e-label-validate (str)
|
||||||
"Validate label STR.
|
"Validate label STR.
|
||||||
@ -53,7 +53,7 @@ See `mu4e-label-regex' for the definition of the valid format."
|
|||||||
(valid-rx (rx bos (regex mu4e-label-regex) eos)))
|
(valid-rx (rx bos (regex mu4e-label-regex) eos)))
|
||||||
;; ii. must not start with + or -
|
;; ii. must not start with + or -
|
||||||
(when (or (char-equal first ?+) (char-equal first ?-))
|
(when (or (char-equal first ?+) (char-equal first ?-))
|
||||||
(mu4e-warn "labels cannot starts with '%c'" first))
|
(mu4e-warn "labels cannot start with '%c'" first))
|
||||||
;; iii. match the regexp
|
;; iii. match the regexp
|
||||||
(unless (string-match-p valid-rx str)
|
(unless (string-match-p valid-rx str)
|
||||||
(mu4e-warn "not a valid label: %S" str)))
|
(mu4e-warn "not a valid label: %S" str)))
|
||||||
@ -63,7 +63,7 @@ See `mu4e-label-regex' for the definition of the valid format."
|
|||||||
"Parse a string a DELTA-EXPRS.
|
"Parse a string a DELTA-EXPRS.
|
||||||
|
|
||||||
If empty, return nil. Otherwise, raise an error if it is invalid.
|
If empty, return nil. Otherwise, raise an error if it is invalid.
|
||||||
Otherwise, return a list with the invidual elements."
|
Otherwise, return a list with the individual elements."
|
||||||
(seq-map (lambda (delta-expr)
|
(seq-map (lambda (delta-expr)
|
||||||
(when (string-empty-p delta-expr)
|
(when (string-empty-p delta-expr)
|
||||||
(mu4e-warn "delta-expression cannot be empty"))
|
(mu4e-warn "delta-expression cannot be empty"))
|
||||||
@ -80,18 +80,14 @@ Otherwise, return a list with the invidual elements."
|
|||||||
|
|
||||||
(defun mu4e--labels-completion-at-point ()
|
(defun mu4e--labels-completion-at-point ()
|
||||||
"Provide completion when entering a label delta expressions."
|
"Provide completion when entering a label delta expressions."
|
||||||
(cond
|
(when (looking-back
|
||||||
((not (looking-back "[^ \t]*" nil))
|
(rx (any "+" "-")
|
||||||
(let ((bounds (bounds-of-thing-at-point 'word)))
|
(group
|
||||||
(list (or (car bounds) (point))
|
(opt (regex mu4e-label-regex))))
|
||||||
(or (cdr bounds) (point)))))
|
(line-beginning-position))
|
||||||
((looking-back
|
|
||||||
(rx (any "+" "-")
|
|
||||||
(group
|
|
||||||
(opt (regex mu4e-label-regex)))) nil)
|
|
||||||
(list (match-beginning 1)
|
(list (match-beginning 1)
|
||||||
(match-end 1)
|
(match-end 1)
|
||||||
mu4e-labels-list))))
|
mu4e-labels-list)))
|
||||||
|
|
||||||
(defvar mu4e-minibuffer-label-expr-map
|
(defvar mu4e-minibuffer-label-expr-map
|
||||||
(let ((map (copy-keymap minibuffer-local-map)))
|
(let ((map (copy-keymap minibuffer-local-map)))
|
||||||
@ -103,7 +99,7 @@ Otherwise, return a list with the invidual elements."
|
|||||||
"Ask for a label delta +/ expression.
|
"Ask for a label delta +/ expression.
|
||||||
|
|
||||||
I.e., a sequence of 1 or more space-separated labels, each
|
I.e., a sequence of 1 or more space-separated labels, each
|
||||||
prefixed with \"+\" for addding the label, or \"-\" for removing
|
prefixed with \"+\" for adding the label, or \"-\" for removing
|
||||||
it."
|
it."
|
||||||
(minibuffer-with-setup-hook
|
(minibuffer-with-setup-hook
|
||||||
(lambda ()
|
(lambda ()
|
||||||
@ -124,7 +120,8 @@ Update the label cache while doing so."
|
|||||||
(let ((deltas (mu4e-label-parse-delta-exprs expr)))
|
(let ((deltas (mu4e-label-parse-delta-exprs expr)))
|
||||||
;; update cache
|
;; update cache
|
||||||
(seq-do (lambda (delta-label)
|
(seq-do (lambda (delta-label)
|
||||||
(cl-pushnew (substring delta-label 1) mu4e-labels-list))
|
(cl-pushnew (substring delta-label 1) mu4e-labels-list
|
||||||
|
:test #'equal))
|
||||||
deltas)
|
deltas)
|
||||||
;; maybe pass as list?
|
;; maybe pass as list?
|
||||||
(mu4e--server-label docid (string-join deltas " "))))
|
(mu4e--server-label docid (string-join deltas " "))))
|
||||||
|
|||||||
Reference in New Issue
Block a user