Merge PR #418 from blc/static

master
Basil L. Contovounesios 1 year ago
commit 4e8e5fae48
No known key found for this signature in database
GPG Key ID: 598403058CAFA86C
  1. 62
      dash.el

@ -30,6 +30,15 @@
;;; Code: ;;; Code:
(eval-when-compile (eval-when-compile
(unless (fboundp 'static-if)
(defmacro static-if (condition then-form &rest else-forms)
"Expand to THEN-FORM or ELSE-FORMS based on compile-time CONDITION.
Polyfill for Emacs 30 `static-if'."
(declare (debug (sexp sexp &rest sexp)) (indent 2))
(if (eval condition lexical-binding)
then-form
(cons 'progn else-forms))))
;; TODO: Emacs 24.3 first introduced `gv', so remove this and all ;; TODO: Emacs 24.3 first introduced `gv', so remove this and all
;; calls to `defsetf' when support for earlier versions is dropped. ;; calls to `defsetf' when support for earlier versions is dropped.
(unless (fboundp 'gv-define-setter) (unless (fboundp 'gv-define-setter)
@ -1036,13 +1045,9 @@ See also: `-first-item', etc."
(declare (pure t) (side-effect-free t)) (declare (pure t) (side-effect-free t))
(car (last list))) (car (last list)))
;; Use `with-no-warnings' to suppress unbound `-last-item' or (static-if (fboundp 'gv-define-setter)
;; undefined `gv--defsetter' warnings arising from both (gv-define-setter -last-item (val x) `(setcar (last ,x) ,val))
;; `gv-define-setter' and `defsetf' in certain Emacs versions. (defsetf -last-item (x) (val) `(setcar (last ,x) ,val)))
(with-no-warnings
(if (fboundp 'gv-define-setter)
(gv-define-setter -last-item (val x) `(setcar (last ,x) ,val))
(defsetf -last-item (x) (val) `(setcar (last ,x) ,val))))
(defun -butlast (list) (defun -butlast (list)
"Return a list of all items in list except for the last." "Return a list of all items in list except for the last."
@ -2901,16 +2906,14 @@ example:
(let ((cmp -compare-fn)) (let ((cmp -compare-fn))
(cond ((memq cmp '(nil equal)) #'assoc) (cond ((memq cmp '(nil equal)) #'assoc)
((eq cmp #'eq) #'assq) ((eq cmp #'eq) #'assq)
;; Since Emacs 26, `assoc' accepts a custom `testfn'. ((lambda (key alist)
;; Version testing would be simpler here, but feature ;; Since Emacs 26, `assoc' accepts a custom `testfn'.
;; testing gets more brownie points, I guess. ;; Version testing would be simpler here, but feature
((condition-case nil ;; testing gets more brownie points, I guess.
(with-no-warnings (assoc nil () #'eql)) (static-if (condition-case nil
(wrong-number-of-arguments t)) (assoc nil () #'eql)
(lambda (key alist) (wrong-number-of-arguments t))
(--first (and (consp it) (funcall cmp (car it) key)) alist))) (--first (and (consp it) (funcall cmp (car it) key)) alist)
((with-no-warnings
(lambda (key alist)
(assoc key alist cmp))))))) (assoc key alist cmp)))))))
(defun dash--hash-test-fn () (defun dash--hash-test-fn ()
@ -3801,11 +3804,9 @@ See also: `-orfn' and `-not'."
;; Open-code for speed. ;; Open-code for speed.
(cond ((cdr preds) (lambda (&rest args) (--every (apply it args) preds))) (cond ((cdr preds) (lambda (&rest args) (--every (apply it args) preds)))
(preds (car preds)) (preds (car preds))
;; As a `pure' function, this runtime check may generate ((static-if (fboundp 'always)
;; backward-incompatible bytecode for `(-andfn)' at compile-time, #'always
;; but I doubt that's a problem in practice (famous last words). (lambda (&rest _) t)))))
((fboundp 'always) #'always)
((lambda (&rest _) t))))
(defun -iteratefn (fn n) (defun -iteratefn (fn n)
"Return a function FN composed N times with itself. "Return a function FN composed N times with itself.
@ -4067,15 +4068,14 @@ See also `dash-fontify-mode-lighter' and
(if dash-fontify-mode (if dash-fontify-mode
(font-lock-add-keywords nil dash--keywords t) (font-lock-add-keywords nil dash--keywords t)
(font-lock-remove-keywords nil dash--keywords)) (font-lock-remove-keywords nil dash--keywords))
(cond ((fboundp 'font-lock-flush) ;; Added in Emacs 25. (static-if (fboundp 'font-lock-flush)
(font-lock-flush)) ;; Added in Emacs 25.
;; `font-lock-fontify-buffer' unconditionally enables (font-lock-flush)
;; `font-lock-mode' and is marked `interactive-only' in later (when font-lock-mode
;; Emacs versions which have `font-lock-flush', so we guard ;; Unconditionally enables `font-lock-mode' and is marked
;; and pacify as needed, respectively. ;; `interactive-only' in later Emacs versions which have
(font-lock-mode ;; `font-lock-flush'.
(with-no-warnings (font-lock-fontify-buffer))))
(font-lock-fontify-buffer)))))
(defun dash--turn-on-fontify-mode () (defun dash--turn-on-fontify-mode ()
"Enable `dash-fontify-mode' if in an Emacs Lisp buffer." "Enable `dash-fontify-mode' if in an Emacs Lisp buffer."

Loading…
Cancel
Save