master c7b156dce38 1/2: gv.el: Allow use of `ignore` as a place (bug#81217)
Stefan Monnier via Mailing list for Emacs changes <[email protected]>
| Newsgroups | gmane.emacs.diffs |
|---|---|
| Message-ID | <[email protected]> |
branch: master commit c7b156dce38a51aff3096fb34a8fbfccfb6c077c Author: Stefan Monnier <[email protected]> Commit: Stefan Monnier <[email protected]> gv.el: Allow use of `ignore` as a place (bug#81217) * lisp/emacs-lisp/gv.el (error): Delete redundant `gv-expander` definition. (ignore): Add a setter. * doc/lispref/functions.texi (Calling Functions): Document `ignore` as a place. * lisp/xdg.el (xdg-mime-collect-associations): Silence compiler warning. --- doc/lispref/functions.texi | 2 ++ etc/NEWS | 4 ++++ lisp/emacs-lisp/gv.el | 13 +++---------- lisp/xdg.el | 9 +++++---- 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/doc/lispref/functions.texi b/doc/lispref/functions.texi index 53597236da8..876cb702e3b 100644 --- a/doc/lispref/functions.texi +++ b/doc/lispref/functions.texi @@ -1131,6 +1131,8 @@ This function returns @var{argument} and has no side effects. @defun ignore &rest arguments This function ignores any @var{arguments} and returns @code{nil}. +When used as a place (@pxref{Generalized Variables}), the assignment has +simply no effect. @end defun @defun always &rest arguments diff --git a/etc/NEWS b/etc/NEWS index a13e556fa47..c4e02890bbb 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -171,6 +171,10 @@ To install the grammars, use 'M-x markdown-ts-mode-install-parsers'. * Lisp Changes in Emacs 32.1 ++++ +** 'ignore' is now also a place, acting as a "blackhole" like /dev/null. +E.g. (push (new-elem) (pcase (foo) (0 var1) (1 var2) (_ (ignore)))) + +++ ** 'kill-all-local-variables' can kill locals silently and reset the buffer. This function's KILL-PERMANENT argument now accepts the value diff --git a/lisp/emacs-lisp/gv.el b/lisp/emacs-lisp/gv.el index 74bafc6a294..4633461a5dc 100644 --- a/lisp/emacs-lisp/gv.el +++ b/lisp/emacs-lisp/gv.el @@ -576,11 +576,6 @@ See also `incf'." (funcall do `(funcall (car ,gv)) (lambda (v) `(funcall (cdr ,gv) ,v))))))) -(put 'error 'gv-expander - (lambda (do &rest args) - (funcall do `(error . ,args) - (lambda (v) `(progn ,v (error . ,args)))))) - (defun gv-synthetic-place (getter setter) "Special place described by its setter and getter. GETTER and SETTER (typically obtained via `gv-letplace') get and @@ -683,11 +678,9 @@ REF must have been previously obtained with `gv-ref'." ;;; Generalized variables. -;; You'd think no one would write `(setf (error ...) ..)' but it -;; appears naturally as the result of macroexpansion of things like -;; (setf (pcase-exhaustive ...)). -;; We could generalize this to `throw' and `signal', but it seems -;; preferable to wait until there's a concrete need. +;; `error' and `ignore' places come in handy in the default branch +;; of `cond/pcase' places. +(gv-define-setter ignore (store &rest _args) store) ;; A kind of >/dev/null (gv-define-expander error (lambda (_do &rest args) `(error . ,args))) ;; Some Emacs-related place types. diff --git a/lisp/xdg.el b/lisp/xdg.el index ccdaa50477a..736afae4eb4 100644 --- a/lisp/xdg.el +++ b/lisp/xdg.el @@ -346,10 +346,11 @@ which is expected to be ordered by priority as in (forward-line) (dolist (str (xdg-desktop-strings (match-string 1))) (cl-pushnew str - (cond ((eq sec ?D) defaults) - ((eq sec ?A) added) - ((eq sec ?R) removed) - ((eq sec ?M) cached)) + (pcase-exhaustive sec + (?D defaults) + (?A added) + (?R removed) + (?M cached)) :test #'equal)) (while (and (zerop (forward-line)) (/= (following-char) ?\[)))))))