(Emacs)~major change to +oreo/create-toggle-function
Now allows numeric arguments to be passed to the buffer creation function. This is especially useful for ~eshell~ which allows creation of multiple instances using a numeric argument: very useful for managing multiple buffers. It's an optional argument but I err on the side of caution so by default I'll set it to nil if I don't want this feature.
This commit is contained in:
@@ -62,21 +62,38 @@ Like VSCode's toggling feature for just the terminal, but now for
|
|||||||
anything I want.
|
anything I want.
|
||||||
#+begin_src emacs-lisp
|
#+begin_src emacs-lisp
|
||||||
(with-eval-after-load "window"
|
(with-eval-after-load "window"
|
||||||
(defmacro +oreo/create-toggle-function (func-name buf-name buf-create)
|
(defmacro +oreo/create-toggle-function (func-name buf-name
|
||||||
|
buf-create
|
||||||
|
&optional accept-numeric)
|
||||||
"Generate a function named FUNC-NAME that toggles the buffer with
|
"Generate a function named FUNC-NAME that toggles the buffer with
|
||||||
name BUF-NAME, using BUF-CREATE to generate it if necessary.
|
name BUF-NAME, using BUF-CREATE to generate it if necessary.
|
||||||
|
|
||||||
BUF-NAME cannot be a regexp, it must be a fixed name."
|
BUF-NAME cannot be a regexp, it must be a fixed name."
|
||||||
`(defun ,func-name ()
|
(let ((interactive-arg
|
||||||
(interactive)
|
(if accept-numeric '(interactive "p") '(interactive)))
|
||||||
(let* ((buffer (or (get-buffer ,buf-name) (,buf-create)))
|
(arguments
|
||||||
|
(if accept-numeric '(&optional arg) nil))
|
||||||
|
(buffer-name (if accept-numeric
|
||||||
|
`(if (= arg 1)
|
||||||
|
,buf-name
|
||||||
|
(concat ,buf-name "<" (int-to-string arg) ">"))
|
||||||
|
buf-name))
|
||||||
|
(buffer-create (if accept-numeric
|
||||||
|
`(if (= arg 1)
|
||||||
|
(,buf-create)
|
||||||
|
(,buf-create arg))
|
||||||
|
`(,buf-create))))
|
||||||
|
`(defun ,func-name ,arguments
|
||||||
|
,interactive-arg
|
||||||
|
(let* ((buffer (or (get-buffer ,buffer-name)
|
||||||
|
,buffer-create))
|
||||||
(displayed (get-buffer-window buffer)))
|
(displayed (get-buffer-window buffer)))
|
||||||
(cond (displayed
|
(cond (displayed
|
||||||
(select-window displayed)
|
(select-window displayed)
|
||||||
(delete-window))
|
(delete-window))
|
||||||
(t
|
(t
|
||||||
(display-buffer buffer)
|
(display-buffer buffer)
|
||||||
(select-window (get-buffer-window buffer))))))))
|
(select-window (get-buffer-window buffer)))))))))
|
||||||
#+end_src
|
#+end_src
|
||||||
** Auto-run command after-save-hook
|
** Auto-run command after-save-hook
|
||||||
Define a macro that can run a body of functionality on a given set of
|
Define a macro that can run a body of functionality on a given set of
|
||||||
@@ -1407,7 +1424,11 @@ calendar to the kill ring and bind it to "Y".
|
|||||||
(when date
|
(when date
|
||||||
(setq date (encode-time 0 0 0 (nth 1 date) (nth 0 date) (nth 2 date)))
|
(setq date (encode-time 0 0 0 (nth 1 date) (nth 0 date) (nth 2 date)))
|
||||||
(kill-new (format-time-string "%Y-%m-%d" date))))))
|
(kill-new (format-time-string "%Y-%m-%d" date))))))
|
||||||
(+oreo/create-toggle-function +calendar/toggle-calendar "*Calendar*" calendar))
|
(+oreo/create-toggle-function
|
||||||
|
+calendar/toggle-calendar
|
||||||
|
"*Calendar*"
|
||||||
|
calendar
|
||||||
|
nil))
|
||||||
#+end_src
|
#+end_src
|
||||||
** Mail
|
** Mail
|
||||||
Mail is a funny thing; most people use it just for business or
|
Mail is a funny thing; most people use it just for business or
|
||||||
@@ -1704,7 +1725,8 @@ function to pull up the eshell quickly.
|
|||||||
(+oreo/create-toggle-function
|
(+oreo/create-toggle-function
|
||||||
+shell/toggle-eshell
|
+shell/toggle-eshell
|
||||||
"*eshell*"
|
"*eshell*"
|
||||||
eshell))
|
eshell
|
||||||
|
t))
|
||||||
#+end_src
|
#+end_src
|
||||||
*** Eshell pretty symbols and display
|
*** Eshell pretty symbols and display
|
||||||
Pretty symbols and a display record.
|
Pretty symbols and a display record.
|
||||||
@@ -2781,7 +2803,8 @@ Here I configure the REPL for Haskell via the
|
|||||||
(+oreo/create-toggle-function
|
(+oreo/create-toggle-function
|
||||||
+shell/toggle-haskell-repl
|
+shell/toggle-haskell-repl
|
||||||
"*haskell*"
|
"*haskell*"
|
||||||
haskell-interactive-bring))
|
haskell-interactive-bring
|
||||||
|
nil))
|
||||||
#+end_src
|
#+end_src
|
||||||
** Python
|
** Python
|
||||||
Works well for python. If you have ~pyls~ it should be on your path, so
|
Works well for python. If you have ~pyls~ it should be on your path, so
|
||||||
@@ -2827,7 +2850,8 @@ Setup for python shell, including a toggle option
|
|||||||
(+oreo/create-toggle-function
|
(+oreo/create-toggle-function
|
||||||
+shell/python-toggle-repl
|
+shell/python-toggle-repl
|
||||||
"*Python*"
|
"*Python*"
|
||||||
run-python))
|
run-python
|
||||||
|
nil))
|
||||||
#+end_src
|
#+end_src
|
||||||
** YAML
|
** YAML
|
||||||
YAML is a data language which is useful for config files.
|
YAML is a data language which is useful for config files.
|
||||||
@@ -2891,7 +2915,8 @@ development on Emacs.
|
|||||||
(+oreo/create-toggle-function
|
(+oreo/create-toggle-function
|
||||||
+shell/toggle-sly
|
+shell/toggle-sly
|
||||||
"*sly-mrepl for sbcl*"
|
"*sly-mrepl for sbcl*"
|
||||||
sly-mrepl)
|
sly-mrepl
|
||||||
|
nil)
|
||||||
:general
|
:general
|
||||||
; general binds
|
; general binds
|
||||||
(nmap
|
(nmap
|
||||||
|
|||||||
Reference in New Issue
Block a user