refactor(eval): avoid seq-uniq & cl-{first,second}
- While seq.el is likely present, Doom does not guarantee it in interactive sesions like it guarantees cl-lib's presence. - There is no reason to ever use cl-first/cl-second.
This commit is contained in:
parent
5bdfecfa92
commit
7d4b0d22dd
1 changed files with 8 additions and 7 deletions
|
@ -50,7 +50,9 @@
|
||||||
|
|
||||||
(defun +eval-repl-known-repls ()
|
(defun +eval-repl-known-repls ()
|
||||||
"Yield the available repl functions as a list of symbols."
|
"Yield the available repl functions as a list of symbols."
|
||||||
(seq-uniq (mapcar (pcase-lambda (`(,mode ,fn . _)) (list mode fn)) +eval-repls)))
|
(cl-delete-duplicates
|
||||||
|
(mapcar (lambda! ((mode fn &rest _)) (list mode fn))
|
||||||
|
+eval-repls)))
|
||||||
|
|
||||||
(defun +doom-pretty-mode-name (mode)
|
(defun +doom-pretty-mode-name (mode)
|
||||||
"Convert a mode name into a variant nicer for human eyes."
|
"Convert a mode name into a variant nicer for human eyes."
|
||||||
|
@ -82,15 +84,15 @@ human-readable variant of its associated major mode name."
|
||||||
|
|
||||||
(defun +eval-repl-prompt ()
|
(defun +eval-repl-prompt ()
|
||||||
"Prompt the user for the choice of a repl to open."
|
"Prompt the user for the choice of a repl to open."
|
||||||
(let* ((knowns (mapcar (pcase-lambda (`(,mode ,fn)) (list (+doom-pretty-mode-name mode) fn))
|
(let* ((knowns (mapcar (lambda! ((mode fn)) (list (+doom-pretty-mode-name mode) fn))
|
||||||
(+eval-repl-known-repls)))
|
(+eval-repl-known-repls)))
|
||||||
(founds (mapcar (lambda (fn) (list (+eval-pretty-mode-name-from-fn fn) fn))
|
(founds (mapcar (lambda (fn) (list (+eval-pretty-mode-name-from-fn fn) fn))
|
||||||
(+eval-repl-found-repls)))
|
(+eval-repl-found-repls)))
|
||||||
(repls (seq-uniq (append knowns founds)))
|
(repls (cl-delete-duplicates (append knowns founds)))
|
||||||
(names (mapcar #'cl-first repls))
|
(names (mapcar #'car repls))
|
||||||
(choice (or (completing-read "Open a REPL for: " names)
|
(choice (or (completing-read "Open a REPL for: " names)
|
||||||
(user-error "Aborting"))))
|
(user-error "Aborting"))))
|
||||||
(cl-second (assoc choice repls))))
|
(cadr (assoc choice repls))))
|
||||||
|
|
||||||
(defun +eval-repl-from-major-mode ()
|
(defun +eval-repl-from-major-mode ()
|
||||||
"Fetch the repl associated with the current major mode, if there
|
"Fetch the repl associated with the current major mode, if there
|
||||||
|
@ -103,8 +105,7 @@ is one."
|
||||||
prompted for a repl choice, even if the major mode they're in
|
prompted for a repl choice, even if the major mode they're in
|
||||||
already has a known one."
|
already has a known one."
|
||||||
(pcase-let* ((`(,fn ,plist) (+eval-repl-from-major-mode))
|
(pcase-let* ((`(,fn ,plist) (+eval-repl-from-major-mode))
|
||||||
(fn (cond ((or prompt-p (not fn)) (+eval-repl-prompt))
|
(fn (if (or prompt-p (not fn)) (+eval-repl-prompt) fn))
|
||||||
(t fn)))
|
|
||||||
(region (when (use-region-p)
|
(region (when (use-region-p)
|
||||||
(buffer-substring-no-properties (region-beginning)
|
(buffer-substring-no-properties (region-beginning)
|
||||||
(region-end)))))
|
(region-end)))))
|
||||||
|
|
Loading…
Reference in a new issue