From ff323e0fda3e403fd3e2e55c7bfc551238f6797c Mon Sep 17 00:00:00 2001 From: Wilfred Hughes Date: Sat, 19 Nov 2016 14:50:57 +0000 Subject: [PATCH] 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. --- dash.el | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/dash.el b/dash.el index 80f596a..4444a10 100644 --- a/dash.el +++ b/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."