Remove dash/f dependencies; use cl-lib & subr-x more

This commit is contained in:
Henrik Lissner 2017-02-19 18:02:40 -05:00
parent 704099a7b9
commit 2d5d826177
11 changed files with 83 additions and 123 deletions

View file

@ -61,50 +61,49 @@ workgroup."
(persp-buffer-list-restricted)) (persp-buffer-list-restricted))
(t (buffer-list)))) (t (buffer-list))))
(project-root (and (not all-p) (doom-project-root t)))) (project-root (and (not all-p) (doom-project-root t))))
(append (if project-root (if project-root
(funcall (if (eq all-p 'not) '-remove '-filter) (funcall (if (eq all-p 'not) 'cl-remove-if 'cl-remove-if-not)
(lambda (b) (projectile-project-buffer-p b project-root)) (lambda (b) (projectile-project-buffer-p b project-root))
buffers) buffers)
buffers) buffers)))
(list doom-fallback-buffer))))
;;;###autoload ;;;###autoload
(defun doom-real-buffers-list (&optional buffer-list) (defun doom-real-buffers-list (&optional buffer-list)
"Get a list of all buffers (in the current workgroup OR in BUFFER-LIST) that "Get a list of all buffers (in the current workgroup OR in BUFFER-LIST) that
`doom-real-buffer-p' returns non-nil for." `doom-real-buffer-p' returns non-nil for."
(-filter #'doom-real-buffer-p (or buffer-list (doom-buffer-list)))) (cl-remove-if-not 'doom-real-buffer-p (or buffer-list (doom-buffer-list))))
;;;###autoload ;;;###autoload
(defun doom-buffers-in-mode (modes &optional buffer-list) (defun doom-buffers-in-mode (modes &optional buffer-list)
"Get a list of all buffers (in the current workgroup OR in BUFFER-LIST) whose "Get a list of all buffers (in the current workgroup OR in BUFFER-LIST) whose
`major-mode' is one of MODES." `major-mode' is one of MODES."
(--filter (memq (buffer-local-value 'major-mode it) modes) (cl-remove-if-not (lambda (buf) (memq (buffer-local-value 'major-mode it) modes))
(or buffer-list (doom-buffer-list)))) (or buffer-list (doom-buffer-list))))
;;;###autoload ;;;###autoload
(defun doom-visible-windows (&optional window-list) (defun doom-visible-windows (&optional window-list)
"Get a list of the visible windows in the current frame (that aren't popups), "Get a list of the visible windows in the current frame (that aren't popups),
OR return only the visible windows in WINDOW-LIST." OR return only the visible windows in WINDOW-LIST."
(-remove #'doom-popup-p (or window-list (window-list)))) (cl-remove-if 'doom-popup-p (or window-list (window-list))))
;;;###autoload ;;;###autoload
(defun doom-visible-buffers (&optional buffer-list) (defun doom-visible-buffers (&optional buffer-list)
"Get a list of unburied buffers in the current project and workgroup, OR "Get a list of unburied buffers in the current project and workgroup, OR
return only the unburied buffers in BUFFER-LIST (a list of BUFFER-OR-NAMEs)." return only the unburied buffers in BUFFER-LIST (a list of BUFFER-OR-NAMEs)."
(-filter #'get-buffer-window (or buffer-list (doom-buffer-list)))) (cl-remove-if-not 'get-buffer-window (or buffer-list (doom-buffer-list))))
;;;###autoload ;;;###autoload
(defun doom-buried-buffers (&optional buffer-list) (defun doom-buried-buffers (&optional buffer-list)
"Get a list of buried buffers in the current project and workgroup, OR return "Get a list of buried buffers in the current project and workgroup, OR return
only the buried buffers in BUFFER-LIST (a list of BUFFER-OR-NAMEs)." only the buried buffers in BUFFER-LIST (a list of BUFFER-OR-NAMEs)."
(-remove 'get-buffer-window (or buffer-list (doom-buffer-list)))) (cl-remove-if 'get-buffer-window (or buffer-list (doom-buffer-list))))
;;;###autoload ;;;###autoload
(defun doom-matching-buffers (pattern &optional buffer-list) (defun doom-matching-buffers (pattern &optional buffer-list)
"Get a list of all buffers (in the current workgroup OR in BUFFER-LIST) that "Get a list of all buffers (in the current workgroup OR in BUFFER-LIST) that
match the regex PATTERN." match the regex PATTERN."
(--filter (string-match-p pattern (buffer-name it)) (cl-remove-if-not (lambda (buf) (string-match-p pattern (buffer-name buf)))
(or buffer-list (doom-buffer-list)))) (or buffer-list (doom-buffer-list))))
(defun doom--cycle-real-buffers (&optional n) (defun doom--cycle-real-buffers (&optional n)
"Switch to the next buffer N times (previous, if N < 0), skipping over special "Switch to the next buffer N times (previous, if N < 0), skipping over special
@ -148,14 +147,14 @@ a) it isn't a popup (or temporary) window
b) it isn't a special buffer (e.g. scratch or *messages* buffer) b) it isn't a special buffer (e.g. scratch or *messages* buffer)
c) and its major-mode or buffer-name-matching regexp isn't in c) and its major-mode or buffer-name-matching regexp isn't in
`doom-buffers-unreal'." `doom-buffers-unreal'."
(let ((buffer (window-normalize-buffer buffer-or-name))) (when-let (buffer (ignore-errors (window-normalize-buffer buffer-or-name)))
(when (buffer-live-p buffer) (or (eq buffer (doom-fallback-buffer))
(not (or (doom-popup-p (get-buffer-window buffer)) (not (or (doom-popup-p (get-buffer-window buffer))
(eq (buffer-name buffer) doom-fallback-buffer) (cl-some (lambda (rule)
(--any? (and (stringp it) (string-match-p it (buffer-name buffer))) (and (stringp rule) (string-match-p rule (buffer-name buffer))))
doom-buffers-unreal) doom-buffers-unreal)
(with-current-buffer buffer (with-current-buffer buffer
(apply 'derived-mode-p (-filter 'symbolp doom-buffers-unreal)))))))) (apply 'derived-mode-p (cl-remove-if-not 'symbolp doom-buffers-unreal))))))))
;;;###autoload ;;;###autoload
(defun doom/next-buffer () (defun doom/next-buffer ()
@ -222,9 +221,11 @@ See `doom-real-buffer-p' for what 'real' means."
(when (and assoc (when (and assoc
(not (string= process-name "server")) (not (string= process-name "server"))
(process-live-p p) (process-live-p p)
(not (--any? (let ((mode (buffer-local-value 'major-mode it))) (not (cl-some
(eq mode (cdr assoc))) (lambda (buf)
buffer-list))) (let ((mode (buffer-local-value 'major-mode it)))
(eq mode (cdr assoc))))
buffer-list)))
(delete-process p) (delete-process p)
(setq n (1+ n))))) (setq n (1+ n)))))
n)) n))

View file

@ -58,7 +58,7 @@ If already there, do nothing."
(insert "\t") (insert "\t")
(let* ((movement (% (current-column) tab-width)) (let* ((movement (% (current-column) tab-width))
(spaces (if (= 0 movement) tab-width (- tab-width movement)))) (spaces (if (= 0 movement) tab-width (- tab-width movement))))
(insert (s-repeat spaces " "))))) (insert (make-string spaces ? )))))
;;;###autoload ;;;###autoload
(defun doom/dumb-dedent () (defun doom/dumb-dedent ()
@ -157,9 +157,9 @@ from a commented line."
((sp-point-in-comment) ((sp-point-in-comment)
(cond ((eq major-mode 'js2-mode) (cond ((eq major-mode 'js2-mode)
(js2-line-break)) (js2-line-break))
((-contains? '(java-mode php-mode) major-mode) ((memq major-mode '(java-mode php-mode))
(c-indent-new-comment-line)) (c-indent-new-comment-line))
((-contains? '(c-mode c++-mode objc-mode css-mode scss-mode js2-mode) major-mode) ((memq major-mode '(c-mode c++-mode objc-mode css-mode scss-mode js2-mode))
(newline-and-indent) (newline-and-indent)
(insert "* ") (insert "* ")
(indent-according-to-mode)) (indent-according-to-mode))

View file

@ -50,7 +50,7 @@ Examples:
(defun doom-mplist-get (plist &rest keys) (defun doom-mplist-get (plist &rest keys)
"TODO" "TODO"
(if (cdr keys) (if (cdr keys)
(let ((keys (--map (memq it plist) keys)) (let ((keys (mapcar (lambda (key) (memq key plist)) keys))
values) values)
(dolist (forms keys) (dolist (forms keys)
(when forms (when forms
@ -60,6 +60,6 @@ Examples:
;;;###autoload ;;;###autoload
(defun doom-mplist-member (plist &rest keys) (defun doom-mplist-member (plist &rest keys)
(--any-p (memq it plist) keys)) (cl-some (lambda (key) (memq key plist)) keys))

View file

@ -237,7 +237,7 @@ appropriate."
(defun doom/packages-update () (defun doom/packages-update ()
"Interactive command for updating packages." "Interactive command for updating packages."
(interactive) (interactive)
(let ((packages (cl-sort (doom-get-outdated-packages) 'doom--sort-alpha))) (let ((packages (sort (doom-get-outdated-packages) 'doom--sort-alpha)))
(cond ((not packages) (cond ((not packages)
(message "Everything is up-to-date")) (message "Everything is up-to-date"))

View file

@ -31,7 +31,7 @@ possible rules."
;;;###autoload ;;;###autoload
(defun doom-popup-windows () (defun doom-popup-windows ()
"Get a list of open poups." "Get a list of open poups."
(-filter 'doom-popup-p (window-list))) (cl-remove-if-not 'doom-popup-p (window-list)))
;;;###autoload ;;;###autoload
(defun doom/popup-restore () (defun doom/popup-restore ()
@ -76,8 +76,9 @@ possible rules."
"Closes all open popups. If DONT-KILL is non-nil, don't kill their buffers." "Closes all open popups. If DONT-KILL is non-nil, don't kill their buffers."
(interactive) (interactive)
(let* ((orig-win (selected-window)) (let* ((orig-win (selected-window))
(popups (--filter (and (doom-popup-p it) (not (eq it orig-win))) (popups (cl-remove-if-not (lambda (win) (and (doom-popup-p win)
(window-list)))) (not (eq win orig-win))))
(window-list))))
(when popups (when popups
(setq doom-popup-history (mapcar 'doom--popup-data (doom-popup-windows))) (setq doom-popup-history (mapcar 'doom--popup-data (doom-popup-windows)))
(let (doom-popup-remember-history) (let (doom-popup-remember-history)

View file

@ -1,31 +1,29 @@
;;; core-lib.el ;;; core-lib.el
(require 'dash) (require 'cl-lib)
(require 's) (eval-when-compile
(require 'f) (require 'subr-x))
(eval-when-compile (require 'cl-lib))
(defvar __DIR__ nil "The directory of the currently loaded file (set by `@load')") ;; I don't use use-package for these to save on the `fboundp' lookups it does
(defvar __FILE__ nil "The full path of the currently loaded file (set by `@load')") ;; for its :commands property.
(mapc (lambda (sym) (autoload sym "async"))
'(async-start async-start-process async-byte-recompile-directory))
(defun __DIR__ () (mapc (lambda (sym) (autoload sym "persistent-soft"))
"Get the full path to the current file's parent folder." '(persistent-soft-exists-p persistent-soft-fetch persistent-soft-flush persistent-soft-store))
(or __DIR__
(and load-file-name (f-dirname load-file-name))
(and buffer-file-name (f-dirname buffer-file-name))
default-directory
(and (bound-and-true-p byte-compile-current-file)
(f-dirname byte-compile-current-file))
(error "__DIR__ is unset")))
(defun __FILE__ () (mapc (lambda (sym) (autoload sym "s"))
"Get the full path to the current file." '(s-trim s-trim-left s-trim-right s-chomp s-collapse-whitespace s-word-wrap
(or __FILE__ s-center s-pad-left s-pad-right s-truncate s-left s-right s-chop-suffix
load-file-name s-chop-suffixes s-chop-prefix s-chop-prefixes s-shared-start s-shared-end
buffer-file-name s-repeat s-concat s-prepend s-append s-lines s-match s-match-strings-all
(and (bound-and-true-p byte-compile-current-file) s-matched-positions-all s-slice-at s-split s-split-up-to s-join s-equals?
byte-compile-current-file) s-less? s-matches? s-blank? s-present? s-ends-with? s-starts-with? s-contains?
(error "__FILE__ is unset"))) s-lowercase? s-uppercase? s-mixedcase? s-capitalized? s-numeric? s-replace
s-replace-all s-downcase s-upcase s-capitalize s-titleize s-with s-index-of
s-reverse s-presence s-format s-lex-format s-count-matches s-wrap s-split-words
s-lower-camel-case s-upper-camel-case s-snake-case s-dashed-words
s-capitalized-words s-titleized-words s-word-initials))
;; ;;
@ -91,15 +89,15 @@ Examples:
(if (cdr-safe (cadr val)) (if (cdr-safe (cadr val))
(cadr val) (cadr val)
(list (cadr val))) (list (cadr val)))
(list func-or-forms)))) (list func-or-forms)))
(macroexp-progn forms)
(mapcar (lambda (f) ;; Maybe use `cl-loop'?
(let ((func (if (symbolp f) `(quote ,f) `(lambda (&rest _) ,@func-or-forms)))) (dolist (fn funcs)
(macroexp-progn (setq fn (if (symbolp fn) `(quote ,fn) `(lambda (&rest _) ,@func-or-forms)))
(mapcar (lambda (h) (dolist (h (if (listp hook) hook (list hook)))
`(add-hook ',(if quoted-p h (intern (format "%s-hook" h))) ,func)) (push `(add-hook ',(if quoted-p h (intern (format "%s-hook" h))) ,fn)
(-list hook))))) forms)))
funcs)))) `(progn ,@(reverse forms))))
(defmacro @associate (mode &rest plist) (defmacro @associate (mode &rest plist)
"Associate a major or minor mode to certain patterns and project files." "Associate a major or minor mode to certain patterns and project files."
@ -120,7 +118,7 @@ Examples:
(or ,(not files) (or ,(not files)
(and (boundp ',mode) (and (boundp ',mode)
(not ,mode) (not ,mode)
(doom-project-has-files ,@(-list files)))) (doom-project-has-files ,@(if (listp files) files (list files)))))
(or (not ,pred) (or (not ,pred)
(funcall ,pred buffer-file-name))) (funcall ,pred buffer-file-name)))
(,mode 1))) (,mode 1)))

View file

@ -36,21 +36,9 @@
(@def-setting :popup (&rest rules) (@def-setting :popup (&rest rules)
"Prepend a new popup rule to `shackle-rules'." "Prepend a new popup rule to `shackle-rules'."
(if (not (-all-p 'listp rules)) (if (cl-every 'listp rules)
`(push ',rules shackle-rules) `(nconc shackle-rules ',rules)
(let (real-rules) `(push ',rules shackle-rules)))
(dolist (rule rules)
(let ((pattern (car rule))
(plist (cdr rule)))
;; Align popups by default (error if this doesn't happen)
(unless (plist-member plist :align)
(plist-put plist :align t))
;; Select popups by default
(unless (or (plist-member plist :select)
(plist-member plist :noselect))
(plist-put plist :select t))
(push (cons pattern plist) real-rules)))
`(setq shackle-rules (append ',real-rules shackle-rules)))))
;; ;;

View file

@ -33,8 +33,10 @@
(defun doom*projectile-cache-current-file (orig-fun &rest args) (defun doom*projectile-cache-current-file (orig-fun &rest args)
"Don't cache ignored files." "Don't cache ignored files."
(unless (--any (f-descendant-of? buffer-file-name it) (unless (cl-some (lambda (path)
(projectile-ignored-directories)) (string-prefix-p buffer-file-name
(expand-file-name path)))
(projectile-ignored-directories))
(apply orig-fun args))) (apply orig-fun args)))
(advice-add 'projectile-cache-current-file :around 'doom*projectile-cache-current-file)) (advice-add 'projectile-cache-current-file :around 'doom*projectile-cache-current-file))

View file

@ -214,11 +214,13 @@ file."
,@forms)) ,@forms))
(defsubst doom--prepare-modeline-segments (segments) (defsubst doom--prepare-modeline-segments (segments)
(-non-nil (delq
(--map (if (stringp it) nil
it (mapcar (lambda (seg)
(list (intern (format "doom-modeline-segment--%s" (symbol-name it))))) (if (stringp seg)
segments))) seg
(list (intern (format "doom-modeline-segment--%s" (symbol-name seg))))))
segments)))
(defmacro @def-modeline (name lhs &optional rhs) (defmacro @def-modeline (name lhs &optional rhs)
"Defines a modeline format and byte-compiles it. "Defines a modeline format and byte-compiles it.

View file

@ -138,38 +138,8 @@ enable multiple minor modes for the same regexp.")
(require 'core-lib) (require 'core-lib)
(require 'core-os) ; consistent behavior across Oses (require 'core-os) ; consistent behavior across Oses
(doom-initialize-autoloads) (doom-initialize-autoloads)
(unless noninteractive (unless noninteractive
(@def-package anaphora
:commands (awhen aif acond awhile))
(@def-package async
:commands (async-start
async-start-process
async-byte-recompile-directory))
(@def-package persistent-soft
:preface (defvar pcache-directory (concat doom-cache-dir "pcache/"))
:commands (persistent-soft-exists-p
persistent-soft-fetch
persistent-soft-flush
persistent-soft-store))
(@def-package ht
:commands (ht-create ht-merge ht-copy ht-select ht-reject ht-select-keys
ht-get ht-keys ht-values ht-items ht-find ht-size
ht-set! ht-update! ht-remove! ht-clear! ht-reject!
ht-map ht-each
ht? ht-contains? ht-equal? ht-empty?
ht->alist ht->plist
ht<-alist ht<-plist
ht ht-amap ht-aeach))
(@def-package smex
:commands (smex smex-major-mode-commands)
:config
(setq smex-save-file (concat doom-cache-dir "/smex-items"))
(smex-initialize))
(require 'core-ui) ; draw me like one of your French editors (require 'core-ui) ; draw me like one of your French editors
(require 'core-popups) ; taming sudden yet inevitable windows (require 'core-popups) ; taming sudden yet inevitable windows
(require 'core-editor) ; baseline configuration for text editing (require 'core-editor) ; baseline configuration for text editing

View file

@ -2,11 +2,9 @@
;;; core/packages.el ;;; core/packages.el
;; core packages ;; core packages
(@package anaphora)
(@package async) (@package async)
(@package persistent-soft) (@package persistent-soft)
(@package ht) (@package s)
(@package smex)
;; core-os.el ;; core-os.el
(when IS-MAC (when IS-MAC