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))
(t (buffer-list))))
(project-root (and (not all-p) (doom-project-root t))))
(append (if project-root
(funcall (if (eq all-p 'not) '-remove '-filter)
(lambda (b) (projectile-project-buffer-p b project-root))
buffers)
buffers)
(list doom-fallback-buffer))))
(if project-root
(funcall (if (eq all-p 'not) 'cl-remove-if 'cl-remove-if-not)
(lambda (b) (projectile-project-buffer-p b project-root))
buffers)
buffers)))
;;;###autoload
(defun doom-real-buffers-list (&optional buffer-list)
"Get a list of all buffers (in the current workgroup OR in BUFFER-LIST) that
`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
(defun doom-buffers-in-mode (modes &optional buffer-list)
"Get a list of all buffers (in the current workgroup OR in BUFFER-LIST) whose
`major-mode' is one of MODES."
(--filter (memq (buffer-local-value 'major-mode it) modes)
(or buffer-list (doom-buffer-list))))
(cl-remove-if-not (lambda (buf) (memq (buffer-local-value 'major-mode it) modes))
(or buffer-list (doom-buffer-list))))
;;;###autoload
(defun doom-visible-windows (&optional window-list)
"Get a list of the visible windows in the current frame (that aren't popups),
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
(defun doom-visible-buffers (&optional buffer-list)
"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)."
(-filter #'get-buffer-window (or buffer-list (doom-buffer-list))))
(cl-remove-if-not 'get-buffer-window (or buffer-list (doom-buffer-list))))
;;;###autoload
(defun doom-buried-buffers (&optional buffer-list)
"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)."
(-remove 'get-buffer-window (or buffer-list (doom-buffer-list))))
(cl-remove-if 'get-buffer-window (or buffer-list (doom-buffer-list))))
;;;###autoload
(defun doom-matching-buffers (pattern &optional buffer-list)
"Get a list of all buffers (in the current workgroup OR in BUFFER-LIST) that
match the regex PATTERN."
(--filter (string-match-p pattern (buffer-name it))
(or buffer-list (doom-buffer-list))))
(cl-remove-if-not (lambda (buf) (string-match-p pattern (buffer-name buf)))
(or buffer-list (doom-buffer-list))))
(defun doom--cycle-real-buffers (&optional n)
"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)
c) and its major-mode or buffer-name-matching regexp isn't in
`doom-buffers-unreal'."
(let ((buffer (window-normalize-buffer buffer-or-name)))
(when (buffer-live-p buffer)
(not (or (doom-popup-p (get-buffer-window buffer))
(eq (buffer-name buffer) doom-fallback-buffer)
(--any? (and (stringp it) (string-match-p it (buffer-name buffer)))
doom-buffers-unreal)
(with-current-buffer buffer
(apply 'derived-mode-p (-filter 'symbolp doom-buffers-unreal))))))))
(when-let (buffer (ignore-errors (window-normalize-buffer buffer-or-name)))
(or (eq buffer (doom-fallback-buffer))
(not (or (doom-popup-p (get-buffer-window buffer))
(cl-some (lambda (rule)
(and (stringp rule) (string-match-p rule (buffer-name buffer))))
doom-buffers-unreal)
(with-current-buffer buffer
(apply 'derived-mode-p (cl-remove-if-not 'symbolp doom-buffers-unreal))))))))
;;;###autoload
(defun doom/next-buffer ()
@ -222,9 +221,11 @@ See `doom-real-buffer-p' for what 'real' means."
(when (and assoc
(not (string= process-name "server"))
(process-live-p p)
(not (--any? (let ((mode (buffer-local-value 'major-mode it)))
(eq mode (cdr assoc)))
buffer-list)))
(not (cl-some
(lambda (buf)
(let ((mode (buffer-local-value 'major-mode it)))
(eq mode (cdr assoc))))
buffer-list)))
(delete-process p)
(setq n (1+ n)))))
n))

View file

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

View file

@ -50,7 +50,7 @@ Examples:
(defun doom-mplist-get (plist &rest keys)
"TODO"
(if (cdr keys)
(let ((keys (--map (memq it plist) keys))
(let ((keys (mapcar (lambda (key) (memq key plist)) keys))
values)
(dolist (forms keys)
(when forms
@ -60,6 +60,6 @@ Examples:
;;;###autoload
(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 ()
"Interactive command for updating packages."
(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)
(message "Everything is up-to-date"))

View file

@ -31,7 +31,7 @@ possible rules."
;;;###autoload
(defun doom-popup-windows ()
"Get a list of open poups."
(-filter 'doom-popup-p (window-list)))
(cl-remove-if-not 'doom-popup-p (window-list)))
;;;###autoload
(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."
(interactive)
(let* ((orig-win (selected-window))
(popups (--filter (and (doom-popup-p it) (not (eq it orig-win)))
(window-list))))
(popups (cl-remove-if-not (lambda (win) (and (doom-popup-p win)
(not (eq win orig-win))))
(window-list))))
(when popups
(setq doom-popup-history (mapcar 'doom--popup-data (doom-popup-windows)))
(let (doom-popup-remember-history)

View file

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

View file

@ -36,21 +36,9 @@
(@def-setting :popup (&rest rules)
"Prepend a new popup rule to `shackle-rules'."
(if (not (-all-p 'listp rules))
`(push ',rules shackle-rules)
(let (real-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)))))
(if (cl-every 'listp rules)
`(nconc shackle-rules ',rules)
`(push ',rules shackle-rules)))
;;

View file

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

View file

@ -214,11 +214,13 @@ file."
,@forms))
(defsubst doom--prepare-modeline-segments (segments)
(-non-nil
(--map (if (stringp it)
it
(list (intern (format "doom-modeline-segment--%s" (symbol-name it)))))
segments)))
(delq
nil
(mapcar (lambda (seg)
(if (stringp seg)
seg
(list (intern (format "doom-modeline-segment--%s" (symbol-name seg))))))
segments)))
(defmacro @def-modeline (name lhs &optional rhs)
"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-os) ; consistent behavior across Oses
(doom-initialize-autoloads)
(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-popups) ; taming sudden yet inevitable windows
(require 'core-editor) ; baseline configuration for text editing

View file

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