Fix setf on emacs23 (#205)

`gv-define-simple-setter` is not defined on Emacs 23, so we need to use
the macro `defsetf` on Emacs 23. `defsetf` is not autoloaded, so we must
require 'cl before using it. We don't need to load 'cl on later Emacs
versions.

However, the whole form is macro-expanded on all Emacs versions. Emacs
24+ assumes that `(defsetf ...)` is a function call because it hasn't
loaded 'cl. This generates byte-compile warnings about unused variables
and nonexistent functions, so silence those.
master
Wilfred Hughes 9 years ago committed by Matus Goljer
parent f04df47f47
commit ff323e0fda
  1. 16
      dash.el

@ -578,14 +578,26 @@ Alias: `-any'"
\(fn LIST)")
(gv-define-simple-setter -first-item setcar)
;; TODO: emacs23 support, when dropped remove the condition
(eval-when-compile
(require 'cl)
(if (fboundp 'gv-define-simple-setter)
(gv-define-simple-setter -first-item setcar)
(require 'cl)
(with-no-warnings
(defsetf -first-item (x) (val) `(setcar ,x ,val)))))
(defun -last-item (list)
"Return the last item of LIST, or nil on an empty list."
(declare (pure t) (side-effect-free t))
(car (last list)))
(gv-define-setter -last-item (val x) `(setcar (last ,x) ,val))
;; TODO: emacs23 support, when dropped remove the condition
(eval-when-compile
(if (fboundp 'gv-define-setter)
(gv-define-setter -last-item (val x) `(setcar (last ,x) ,val))
(with-no-warnings
(defsetf -last-item (x) (val) `(setcar (last ,x) ,val)))))
(defun -butlast (list)
"Return a list of all items in list except for the last."

Loading…
Cancel
Save