core-defuns: remove cl-lib dependency

This commit is contained in:
Henrik Lissner 2016-05-12 02:36:11 -04:00
parent ebf283e5a8
commit ef4b8c5b65

View file

@ -1,5 +1,3 @@
(eval-when-compile (require 'cl-lib))
;; Backwards compatible `with-eval-after-load' ;; Backwards compatible `with-eval-after-load'
(unless (fboundp 'with-eval-after-load) (unless (fboundp 'with-eval-after-load)
(defmacro with-eval-after-load (file &rest body) (defmacro with-eval-after-load (file &rest body)
@ -68,35 +66,35 @@ Examples:
(if (listp hook) hook (list hook))))) funcs) (if (listp hook) hook (list hook))))) funcs)
`(progn ,@forms))) `(progn ,@forms)))
(cl-defmacro associate! (mode &key minor (defmacro associate! (mode &rest rest)
&key in
&key match
&key files
&allow-other-keys)
"Associate a major or minor mode to certain patterns and project files." "Associate a major or minor mode to certain patterns and project files."
(declare (indent 1)) (declare (indent 1))
`(progn (let ((minor (plist-get rest :minor))
(,@(cond ((or files in) (in (plist-get rest :in))
(when (and files (not (or (listp files) (stringp files)))) (match (plist-get rest :match))
(user-error "associate! :files expects a string or list of strings")) (files (plist-get rest :files)))
(let ((hook-name (intern (format "narf--init-mode-%s" mode)))) `(progn
`(progn (,@(cond ((or files in)
(defun ,hook-name () (when (and files (not (or (listp files) (stringp files))))
(when (and ,(if match `(if buffer-file-name (string-match-p ,match buffer-file-name)) t) (user-error "associate! :files expects a string or list of strings"))
(or ,(not files) (let ((hook-name (intern (format "narf--init-mode-%s" mode))))
(and (boundp ',mode) `(progn
(not ,mode) (defun ,hook-name ()
(narf/project-has-files ,@(-list files))))) (when (and ,(if match `(if buffer-file-name (string-match-p ,match buffer-file-name)) t)
(,mode 1))) (or ,(not files)
,@(if (and in (listp in)) (and (boundp ',mode)
(mapcar (lambda (h) `(add-hook ',h ',hook-name)) (not ,mode)
(mapcar (lambda (m) (intern (format "%s-hook" m))) in)) (narf/project-has-files ,@(-list files)))))
`((add-hook 'find-file-hook ',hook-name)))))) (,mode 1)))
(match ,@(if (and in (listp in))
`(add-to-list ',(if minor 'narf-auto-minor-mode-alist 'auto-mode-alist) (mapcar (lambda (h) `(add-hook ',h ',hook-name))
(cons ,match ',mode))) (mapcar (lambda (m) (intern (format "%s-hook" m))) in))
(t (user-error "associate! invalid rules for mode [%s] (in %s) (match %s) (files %s)" `((add-hook 'find-file-hook ',hook-name))))))
mode in match files)))))) (match
`(add-to-list ',(if minor 'narf-auto-minor-mode-alist 'auto-mode-alist)
(cons ,match ',mode)))
(t (user-error "associate! invalid rules for mode [%s] (in %s) (match %s) (files %s)"
mode in match files)))))))
(defmacro def-project-type! (name lighter &rest body) (defmacro def-project-type! (name lighter &rest body)
"Define a minor mode for a specific framework, library or project type." "Define a minor mode for a specific framework, library or project type."
@ -230,7 +228,7 @@ Examples:
(t (user-error "Invalid key %s" key))) (t (user-error "Invalid key %s" key)))
forms) forms)
(cl-incf i)) (setq i (1+ i)))
`(progn ,@(apply #'nconc (delete nil (delete (list nil) (reverse forms)))))))) `(progn ,@(apply #'nconc (delete nil (delete (list nil) (reverse forms))))))))