[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/helm 9c539c683e 3/4: Make special symbols in *acase more e
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/helm 9c539c683e 3/4: Make special symbols in *acase more explicit |
Date: |
Tue, 17 Dec 2024 04:06:05 -0500 (EST) |
branch: elpa/helm
commit 9c539c683e8ddd1bf79d451f07a97cfafde67880
Author: Thierry Volpiatto <thievol@posteo.net>
Commit: Thierry Volpiatto <thievol@posteo.net>
Make special symbols in *acase more explicit
This make clear what the code does and prevent special cases where
EXPR is one of dst or guard and is checked in a list.
The symbols guard and dst are now replaced by guard* and dst*.
---
helm-command.el | 4 ++--
helm-core.el | 16 ++++++++--------
helm-elisp.el | 54 +++++++++++++++++++++++++++---------------------------
helm-files.el | 8 ++++----
helm-grep.el | 2 +-
helm-imenu.el | 8 ++++----
helm-lib.el | 48 +++++++++++++++++++++++++-----------------------
helm-mode.el | 10 +++++-----
helm-ring.el | 6 +++---
helm-utils.el | 8 ++++----
10 files changed, 83 insertions(+), 81 deletions(-)
diff --git a/helm-command.el b/helm-command.el
index 7ff93b66ae..e5af2fccdc 100644
--- a/helm-command.el
+++ b/helm-command.el
@@ -320,9 +320,9 @@ Arg HISTORY default to `extended-command-history'."
:fuzzy-match helm-M-x-fuzzy-match)))
(prompt (concat (helm-acase helm-M-x-prefix-argument
(- "-")
- ((guard (and (consp it) (car it)))
+ ((guard* (and (consp it) (car it)))
(if (eq guard 4) "C-u " (format "%d " guard)))
- ((guard (integerp it)) (format "%d " it)))
+ ((guard* (integerp it)) (format "%d " it)))
"M-x ")))
(setq helm-M-x--timer (run-at-time 1 0.1 #'helm-M-x--notify-prefix-arg))
;; Fix Bug#2250, add `helm-move-selection-after-hook' which
diff --git a/helm-core.el b/helm-core.el
index db070f1c96..bb64bcfeea 100644
--- a/helm-core.el
+++ b/helm-core.el
@@ -2386,8 +2386,8 @@ show ARG number of candidates."
(with-helm-default-directory (helm-default-directory)
(setq-local helm-candidate-number-limit
(helm-acase arg
- ((guard (consp arg)) nil)
- ((guard (numberp arg)) it)
+ ((guard* (consp arg)) nil)
+ ((guard* (numberp arg)) it)
(t (default-value 'helm-candidate-number-limit))))
(helm-set-source-filter
(list (helm-get-current-source))))))))
@@ -3465,7 +3465,7 @@ The function used to display `helm-buffer' by calling
helm-reuse-last-window-split-state)
(helm-acase helm-split-window-default-side
((same other) it) ; take precedence on *-window-side-state.
- ((guard helm--window-side-state) guard)
+ ((guard* helm--window-side-state) guard)
(t it))
helm-split-window-default-side))
(disp-fn (with-current-buffer buffer
@@ -3815,9 +3815,9 @@ See :after-init-hook and :before-init-hook in
`helm-source'."
;; etc...
(dolist (s sources)
(helm-acase (assoc-default hook s)
- ((guard (and (functionp it) (not (symbolp it))))
+ ((guard* (and (functionp it) (not (symbolp it))))
(funcall it))
- ((guard (listp it))
+ ((guard* (listp it))
(dolist (h it) (funcall h)))
(t (helm-log-run-hook "helm--run-init-hooks" it)))))
@@ -4752,7 +4752,7 @@ useful when the order of the candidates is meaningful,
e.g. with
(helm--maybe-get-migemo-pattern
pat diacritics))
(helm-acase (split-string pattern
"" t)
- ((guard (string= "!" (car it)))
nil)
+ ((guard* (string= "!" (car it)))
nil)
(t it)))
for p in patterns
;; Multi matches (regexps patterns).
@@ -5341,7 +5341,7 @@ specified as respectively `helm-cand-num' and
`helm-cur-source'."
`(mouse-face highlight
keymap ,map
help-echo ,(helm-acase (get-text-property start
'help-echo)
- ((guard (stringp it))
+ ((guard* (stringp it))
(concat it "\nmouse-1: select
candidate\nmouse-3: menu actions"))
(t "mouse-1: select candidate\nmouse-3:
menu actions")))))
(when num
@@ -6425,7 +6425,7 @@ message \\='no match'."
(with-helm-buffer
(setq minibuffer-completion-confirm
(helm-acase (helm-get-attr 'must-match src)
- ((guard (and (functionp it)
+ ((guard* (and (functionp it)
(helm-get-selection nil nil src)))
(if (funcall it guard) 'exit 'noexit))
(t it)))))
diff --git a/helm-elisp.el b/helm-elisp.el
index d3bb9191b1..4219119d52 100644
--- a/helm-elisp.el
+++ b/helm-elisp.el
@@ -377,18 +377,18 @@ other window according to the value of
(helm-acase (if (member candidate helm-lisp-completion-re-chars-classes)
candidate
(intern-soft candidate))
- ((guard (stringp it))
+ ((guard* (stringp it))
(helm-describe-re-char-classes it))
- ((guard (and (fboundp it) (boundp it)))
+ ((guard* (and (fboundp it) (boundp it)))
(if (member name `(,helm-describe-function-function
,helm-describe-variable-function))
(funcall (intern (format "helm-%s" name)) it)
;; When there is no way to know what to describe
;; prefer describe-function.
(helm-describe-function it)))
- ((guard (fboundp it)) (helm-describe-function it))
- ((guard (boundp it)) (helm-describe-variable it))
- ((guard (facep it)) (helm-describe-face it))))
+ ((guard* (fboundp it)) (helm-describe-function it))
+ ((guard* (boundp it)) (helm-describe-variable it))
+ ((guard* (facep it)) (helm-describe-face it))))
(defun helm-elisp-show-help (candidate &optional name)
"Show full help for the function CANDIDATE.
@@ -415,15 +415,15 @@ the same time to variable and a function."
for sym = (if (string-match "\\`:[[:alpha:]]+:\\'" c)
c (intern-soft c))
for annot = (helm-acase sym
- ((guard (stringp it)) "<reg> ")
- ((guard (commandp it)) "<com> ")
- ((guard (class-p it)) "<cla> ")
- ((guard (cl-generic-p it)) "<gen> ")
- ((guard (fboundp it)) "<fun> ")
- ((guard (keywordp it)) "<kwd> ")
- ((guard (boundp it)) "<var> ")
- ((guard (facep it)) "<fac> ")
- ((guard (helm-group-p it)) "<grp> ")
+ ((guard* (stringp it)) "<reg> ")
+ ((guard* (commandp it)) "<com> ")
+ ((guard* (class-p it)) "<cla> ")
+ ((guard* (cl-generic-p it)) "<gen> ")
+ ((guard* (fboundp it)) "<fun> ")
+ ((guard* (keywordp it)) "<kwd> ")
+ ((guard* (boundp it)) "<var> ")
+ ((guard* (facep it)) "<fac> ")
+ ((guard* (helm-group-p it)) "<grp> ")
(t " "))
collect (cons (concat (helm-aand
(propertize
@@ -444,23 +444,23 @@ Argument NAME allows specifiying what function to use to
display
documentation when SYM name is the same for function and variable."
(let ((doc (condition-case _err
(helm-acase sym
- ((guard (stringp it))
+ ((guard* (stringp it))
(cadr (split-string (helm-describe-re-char-classes-1 it)
"\n")))
- ((guard (class-p it))
+ ((guard* (class-p it))
(cl--class-docstring (cl--find-class it)))
- ((guard (and (fboundp it) (boundp it)))
+ ((guard* (and (fboundp it) (boundp it)))
(if (string= name "describe-variable")
(documentation-property it 'variable-documentation t)
(documentation it t)))
- ((guard (custom-theme-p it))
+ ((guard* (custom-theme-p it))
(documentation-property it 'theme-documentation t))
- ((guard (and (helm-group-p it) (not (fboundp it))))
+ ((guard* (and (helm-group-p it) (not (fboundp it))))
(documentation-property it 'group-documentation t))
- ((guard (fboundp it))
+ ((guard* (fboundp it))
(documentation it t))
- ((guard (boundp it))
+ ((guard* (boundp it))
(documentation-property it 'variable-documentation t))
- ((guard (facep it)) (face-documentation it)))
+ ((guard* (facep it)) (face-documentation it)))
(void-function "Void function -- Not documented"))))
(if (and doc (not (string= doc ""))
;; `documentation' return "\n\n(args...)"
@@ -473,7 +473,7 @@ documentation when SYM name is the same for function and
variable."
;; <https://debbugs.gnu.org/70163>.
(truncate-string-to-width
(helm-acase (split-string (substitute-command-keys doc) "\n")
- ((dst (l &rest args))
+ ((dst* (l &rest args))
(if (string= l "") (cadr args) l)))
end-column nil nil t)
(if (or (symbol-function sym) (boundp sym) (facep sym) (helm-group-p
sym))
@@ -780,16 +780,16 @@ is only used to test DEFAULT."
(defun helm-info-lookup-fallback-source (candidate)
(cl-multiple-value-bind (fn src-name)
(helm-acase (helm-symbolify candidate)
- ((guard (class-p it))
+ ((guard* (class-p it))
(list #'helm-describe-function
"Describe class"))
- ((guard (cl-generic-p it))
+ ((guard* (cl-generic-p it))
(list #'helm-describe-function
"Describe generic function"))
- ((guard (fboundp it))
+ ((guard* (fboundp it))
(list #'helm-describe-function
"Describe function"))
- ((guard (facep it))
+ ((guard* (facep it))
(list #'helm-describe-face
"Describe face"))
(t
diff --git a/helm-files.el b/helm-files.el
index 556dfe7359..bbcc2033c3 100644
--- a/helm-files.el
+++ b/helm-files.el
@@ -2443,7 +2443,7 @@ COUNT is used for incrementing new name if needed."
(string-to-number
(match-string 1 rep))
(helm-acase (match-string 2 rep)
- ((guard (string= it ""))
+ ((guard* (string= it ""))
(length target))
(t (string-to-number it))))
t t rep))
@@ -3316,8 +3316,8 @@ editing absolute fnames in previous Emacs versions."
(defun helm-ff--tramp-cons-or-vector (vector-or-cons)
"Return VECTOR-OR-CONS as a vector."
(helm-acase vector-or-cons
- ((guard (and (consp it) (cdr it))) (vconcat guard))
- ((guard (vectorp it)) it)
+ ((guard* (and (consp it) (cdr it))) (vconcat guard))
+ ((guard* (vectorp it)) it)
(t (error "Wrong type argument: %s" it))))
(defun helm-ff--get-tramp-methods ()
@@ -5221,7 +5221,7 @@ Special commands:
(cl-loop with scale = (image-compute-scaling-factor nil)
for (disp . img) in candidates
for type = (helm-acase (file-name-extension img)
- ((guard (and (member it '("png" "jpg" "jpeg"))
+ ((guard* (and (member it '("png" "jpg" "jpeg"))
(memq
image-dired-thumbnail-storage
'(standard
standard-large))))
'png)
diff --git a/helm-grep.el b/helm-grep.el
index bbc5dfc84e..f354709133 100644
--- a/helm-grep.el
+++ b/helm-grep.el
@@ -541,7 +541,7 @@ Have no effect when grep backend use \"--color=\"."
pipe-switches))
;; Use ack-grep for PCRE based tools.
;; Sometimes ack-grep cmd is ack only so compare by matching ack.
- ((guard (string-match-p "ack" it))
+ ((guard* (string-match-p "ack" it))
(format "%s --smart-case --color %s" it pipe-switches))))
(defun helm-grep--prepare-cmd-line (only-files &optional include zgrep)
diff --git a/helm-imenu.el b/helm-imenu.el
index f610a39171..529d75df7a 100644
--- a/helm-imenu.el
+++ b/helm-imenu.el
@@ -408,9 +408,9 @@ The sexp should be an `all-the-icons' function with its
args."
;; Semantic uses overlays whereas imenu uses
;; markers (Bug#1706).
(setcdr elm (helm-acase (cdr elm) ; Same as [1].
- ((guard (overlayp it))
+ ((guard* (overlayp it))
(copy-overlay it))
- ((guard (or (markerp it) (integerp it)))
+ ((guard* (or (markerp it) (integerp it)))
(copy-marker it))))
(list elm))))))
@@ -444,8 +444,8 @@ The icon is found in `helm-imenu-icon-type-alist', if not
;; (k . v) == (symbol-name . marker)
for bufname = (buffer-name
(helm-acase v
- ((guard (overlayp it)) (overlay-buffer it))
- ((guard (markerp it)) (marker-buffer it))))
+ ((guard* (overlayp it)) (overlay-buffer it))
+ ((guard* (markerp it)) (marker-buffer it))))
for types = (or (helm-imenu--get-prop k)
(list (if (with-current-buffer bufname
(derived-mode-p 'prog-mode))
diff --git a/helm-lib.el b/helm-lib.el
index 70c12b1515..84a73b0164 100644
--- a/helm-lib.el
+++ b/helm-lib.el
@@ -564,30 +564,32 @@ is usable in next condition."
and `cond'.
KEYLIST can be any object that will be compared with `equal' or
-an expression starting with `guard' which is then evaluated.
-Once evaluated `guard' is bound to the returned value that can be
-used in the cdr of clause. When KEYLIST match EXPR or `guard'
-evaluation is non-nil, BODY is executed and `helm-acase' exits
-with its value.
+an expression starting with special symbol `guard*' which is then
+evaluated. Once evaluated the symbol `guard' is bound to the
+returned value that can be used in the cdr of clause. When
+KEYLIST match EXPR or `guard*' sexp evaluation is non-nil, BODY is
+executed and `helm-acase' exits with its value.
-KEYLIST can also be a list starting with `dst' followed by an expression
-suitable for `cl-destructuring-bind'. In this case all elements of `it' are
-bound to the elements of this expression e.g.
+KEYLIST can also be a list starting with special symbol `dst*'
+followed by an expression suitable for `cl-destructuring-bind'.
+In this case all elements of `it' are bound to the elements of
+this expression e.g.
(helm-acase \\='(1 2 3 4 5)
- ((dst (l &rest args)) args))
+ ((dst* (l &rest args)) args))
=> (2 3 4 5)
If KEYLIST is a list, it is compared with EXPR, also each
elements of the list are checked with `member' to see if one
-matches EXPR e.g.
+matches EXPR, as a special case, the special symbols `guard*' and
+`dst*' have to NOT be at start of such list.
The last clause can use `t' or \\='otherwise as KEYLIST to specify a
fallback clause when previous clauses didn't match, if such a clause
starting with `t' or \\='otherwise is specified before last clause it
will override all next clauses, if you want to match an EXPR value equal
to `t' in any clauses quote it, i.e. `'t' or use an explicit
-\(guard (eq it t)).
+\(guard* (eq it t)).
EXPR is bound to a temporary variable called `it' which is
usable in all clauses to refer to EXPR.
@@ -597,8 +599,8 @@ usable in all clauses to refer to EXPR.
(unless (null clauses)
(let* ((clause1 (car clauses))
(key (car clause1))
- (isguard (eq 'guard (car-safe key)))
- (isdst (eq 'dst (car-safe key)))
+ (isguard (eq 'guard* (car-safe key)))
+ (isdst (eq 'dst* (car-safe key)))
(special (or isguard isdst))
(sexp (and isguard (cadr key)))
(dst-sexp (and isdst (cadr key))))
@@ -791,7 +793,7 @@ displayed in BUFNAME."
(defun helm-help-org-cycle ()
"Runs `org-cycle' in `helm-help'."
(helm-acase (helm-iter-next helm-help--iter-org-state)
- ((guard (numberp it)) (org-content))
+ ((guard* (numberp it)) (org-content))
;; See `helm--help-org-prefargs' about `org-cycle' ARG.
(t (org-cycle it))))
@@ -1160,9 +1162,9 @@ Examples:
"Return the representation of ELM as a string.
ELM can be a string, a number or a symbol."
(helm-acase elm
- ((guard (stringp it)) it)
- ((guard (numberp it)) (number-to-string it))
- ((guard (symbolp it)) (symbol-name it))))
+ ((guard* (stringp it)) it)
+ ((guard* (numberp it)) (number-to-string it))
+ ((guard* (symbolp it)) (symbol-name it))))
(defun helm-substring (str width)
"Return the substring of string STR from 0 to WIDTH.
@@ -1377,13 +1379,13 @@ in LIST to be displayed in PROMPT."
(apply #'format
(concat prompt "[y,n,!,q,h]")
(helm-acase prompt-formater
- ((guard (consp it))
+ ((guard* (consp it))
(mapcar (lambda (x)
(if (functionp x)
(funcall x elm)
x))
it))
- ((guard (functionp it))
+ ((guard* (functionp it))
(list (funcall it elm)))
(t (list elm))))
'("y" "n" "!" "q")
@@ -1407,7 +1409,7 @@ This avoid possible infloop when a wrong regexp is
entered in minibuffer."
;; See Issue#2652 and Issue#2653.
(let ((pos (point)))
(helm-acase (re-search-forward regexp bound noerror count)
- ((guard (eql it pos)) nil)
+ ((guard* (eql it pos)) nil)
(t it))))
;;; Symbols routines
@@ -1415,7 +1417,7 @@ This avoid possible infloop when a wrong regexp is
entered in minibuffer."
(defun helm-symbolify (str-or-sym)
"Get symbol of STR-OR-SYM."
(helm-acase str-or-sym
- ((guard (symbolp it)) it)
+ ((guard* (symbolp it)) it)
("" nil)
(t (intern it))))
@@ -1823,7 +1825,7 @@ is same as with PARENT."
It is done according to `helm-current-directory-alist'."
(expand-file-name
(helm-acase major-mode
- ((guard (assoc-default it helm-current-directory-alist))
+ ((guard* (assoc-default it helm-current-directory-alist))
(helm-interpret-value guard))
(t default-directory))))
@@ -2149,7 +2151,7 @@ flex or helm-flex completion style if present."
(or
styles
(helm-acase (cdr (assq from helm-completion-styles-alist))
- ((dst (_l &rest args)) args))
+ ((dst* (_l &rest args)) args))
;; We need to have flex always behind helm, otherwise
;; when matching against e.g. '(foo foobar foao frogo bar
;; baz) with pattern "foo" helm style if before flex will
diff --git a/helm-mode.el b/helm-mode.el
index d0d8b5fdde..9a447e9ae5 100644
--- a/helm-mode.el
+++ b/helm-mode.el
@@ -1433,8 +1433,8 @@ This handler should be used when candidate list doesn't
need to be rebuilt
dynamically otherwise use `helm-completing-read-default-2'."
(let* ((history (or (car-safe hist) hist))
(initial-input (helm-acase init
- ((guard (stringp it)) it)
- ((guard (consp it)) (car it))))
+ ((guard* (stringp it)) it)
+ ((guard* (consp it)) (car it))))
(minibuffer-completion-table collection)
(metadata (or (completion-metadata (or initial-input "") collection
test)
'(metadata)))
@@ -1521,8 +1521,8 @@ This handler uses dynamic matching which allows honouring
`completion-styles'."
(let* ((completion-lazy-hilit t)
(history (or (car-safe hist) hist))
(input (helm-acase init
- ((guard (stringp it)) it)
- ((guard (consp it)) (car it))))
+ ((guard* (stringp it)) it)
+ ((guard* (consp it)) (car it))))
(completion-flex-nospace t)
(minibuffer-completion-table collection)
;; (completion-styles
@@ -2783,7 +2783,7 @@ Can be used for `completion-in-region-function' by
advicing it with an
(when (and (stringp string) exit-fun)
(funcall exit-fun string
(helm-acase (try-completion initial-input collection
predicate)
- ((guard (and (stringp it)
+ ((guard* (and (stringp it)
(or (string-match "/\\'" it)
;; Fix bug#2669.
(string-match "/\\'" string))))
diff --git a/helm-ring.el b/helm-ring.el
index 2aeee576be..18f08346ea 100644
--- a/helm-ring.el
+++ b/helm-ring.el
@@ -325,7 +325,7 @@ yanked string."
(goto-char marker)
(forward-line 0)
(let ((line (helm-acase (thing-at-point 'line)
- ((guard (and (stringp it)
+ ((guard* (and (stringp it)
(not (string-match-p "\\`\n?\\'" it))))
(car (split-string it "[\n\r]")))
(t "<EMPTY LINE>"))))
@@ -620,8 +620,8 @@ See (info \"(emacs) Keyboard Macros\") for detailed infos."
for keys = (if (functionp km)
(kmacro--keys km)
(helm-acase (car km)
- ((guard (vectorp it)) it)
- ((guard (stringp it))
+ ((guard* (vectorp it)) it)
+ ((guard* (stringp it))
(kmacro--to-vector it))))
vconcat keys)))))
diff --git a/helm-utils.el b/helm-utils.el
index 72dc7034cd..5678b964d9 100644
--- a/helm-utils.el
+++ b/helm-utils.el
@@ -938,16 +938,16 @@ Optional arguments START, END and FACE are only here for
debugging purpose."
;; `helm-highlight-matches-around-point-max-lines' is
;; compared as a number by other clauses and return an error.
(never (cl-return-from helm-highlight-current-line))
- ((dst (x . y))
+ ((dst* (x . y))
(setq start-match (save-excursion (forward-line (- x)) (pos-bol))
end-match (save-excursion (forward-line y) (pos-bol))))
- ((guard (or (null it) (zerop it)))
+ ((guard* (or (null it) (zerop it)))
(setq start-match start
end-match end))
- ((guard (< it 0))
+ ((guard* (< it 0))
(setq start-match (save-excursion (forward-line it) (pos-bol))
end-match start))
- ((guard (> it 0))
+ ((guard* (> it 0))
(setq start-match start
end-match (save-excursion (forward-line it) (pos-bol)))))
(catch 'empty-line