emacs: minor changes to index & input methods

This commit is contained in:
Pavel Korytov 2024-01-28 01:58:07 +03:00
parent 95267451f8
commit 5a0b48a17f
6 changed files with 116 additions and 79 deletions

View file

@ -1,5 +1,6 @@
(specifications->manifest
'(
"python-cairosvg"
"python-chess"
"wireshark"
"socat"
@ -20,6 +21,7 @@
"openjdk:jdk"
"node"
"git-filter-repo"
"dnsmasq"
"virt-manager"
"postgresql"
"docker-compose"

View file

@ -17,4 +17,5 @@
"python-isort"
"python-black"
"python-yapf"
"plantuml"))
"plantuml"
"xkb-switch"))

View file

@ -362,10 +362,6 @@ DIR is either 'left or 'right."
(when exwm--connection
(exwm-input--update-global-prefix-keys)))
(defun my/run-in-background (command)
(let ((command-parts (split-string command "[ ]+")))
(apply #'call-process `(,(car command-parts) nil 0 nil ,@(cdr command-parts)))))
(defhydra my/exwm-apps-hydra (:color blue :hint nil)
"
^Apps^

View file

@ -100,6 +100,10 @@
(use-package no-littering
:straight t)
(defun my/run-in-background (command)
(let ((command-parts (split-string command "[ ]+")))
(apply #'call-process `(,(car command-parts) nil 0 nil ,@(cdr command-parts)))))
(setq confirm-kill-emacs 'y-or-n-p)
(use-package general
@ -537,9 +541,19 @@ then it takes a second \\[keyboard-quit] to abort the minibuffer."
(setq default-input-method "russian-computer")
(defun my/toggle-input-method ()
(interactive)
(if (derived-mode-p 'exwm-mode)
(my/run-in-background "xkb-switch -n")
(if (equal (string-trim
(shell-command-to-string "xkb-switch -p"))
"us")
(toggle-input-method)
(my/run-in-background "xkb-switch -s us"))))
(general-define-key
:keymaps 'global
"M-\\" #'toggle-input-method)
"M-\\" #'my/toggle-input-method)
(use-package smartparens
:straight t)
@ -554,14 +568,14 @@ then it takes a second \\[keyboard-quit] to abort the minibuffer."
)
(use-package accent
:straight t
:straight (:host github :repo "SqrtMinusOne/accent")
:init
(general-define-key
:states '(normal)
"gs" #'accent-menu)
"gs" #'accent-company)
(general-define-key
:states '(normal insert)
"M-n" #'accent-menu)
"M-n" #'accent-company)
:commands (accent-menu)
:config
(general-define-key
@ -5419,8 +5433,9 @@ KEYS is a list of cons cells like (<label> . <time>)."
("ll" "ls -la")
("e" "find-file")))
(setq eshell-banner-message "")
(setq eshell-visual-commands
`(,@eshell-visual-commands "jless")))
;; (setq eshell-visual-commands
;; `(,@eshell-visual-commands "jless"))
)
(defvar-local my/eshell-last-command-start-time nil)
@ -8164,18 +8179,9 @@ NAV is a structure as defined by `my/index--nav-get'."
(defun my/index-nav (arg &optional func)
"Navigate the filesystem index.
ARG is the prefix argument. It modifies the behavior of the
command as follows:
- If not in an indexed directory, or in an indexed directory with no
indexed children:
- nil: Select an indexed directory.
- '(4): Select an indexed directory, and select a child indexed
directory if available.
- If in an indexed directory with indexed children (a project):
- nil: Select another indexed directory from the project.
- '(4): Select a top-level indexed directory (the same as nil for
the previous case).
- '(16): The same as '(4) for the previous case.
If ARG is nil, navigate all levels sequentially from the top one.
If ARG is '(4), select another directory from the same level.
FUNC is the function to call with the selected path. It defaults
to `dired' if used interactively."
@ -8184,25 +8190,32 @@ to `dired' if used interactively."
(current-nav (my/index--nav-find-path
nav (expand-file-name default-directory)))
(current-child-navs (alist-get :child-navs current-nav)))
(cond
((or (and (null arg) (null current-child-navs))
(and (equal arg '(4)) current-child-navs))
(funcall
func
(my/index--nav-prompt nav)))
((or (and (equal arg '(4)) (null current-child-navs))
(and (equal arg '(16)) current-child-navs))
(let ((selected (my/index--nav-find-path
nav
(my/index--nav-prompt nav))))
(if-let (child-navs (alist-get :child-navs selected))
(funcall func (my/index--nav-prompt child-navs))
(funcall func (alist-get :path selected)))))
((and (null arg) current-child-navs)
(funcall func (my/index--nav-prompt current-child-navs))))))
(cond ((null arg)
(let ((selected (my/index--nav-find-path
nav
(my/index--nav-prompt nav))))
(if-let (child-navs (alist-get :child-navs selected))
(funcall func (my/index--nav-prompt child-navs))
(funcall func (alist-get :path selected)))))
((and (equal arg '(4)) current-child-navs)
(funcall func (my/index--nav-prompt current-child-navs)))
((and (equal arg '(4)) (null current-child-navs))
(funcall func (my/index--nav-prompt nav))))))
(defun my/index-nav-with-select-file (arg)
(interactive (list current-prefix-arg))
(my/index-nav
arg
(lambda (dir)
(let ((default-directory dir))
(projectile-find-file)))))
(my-leader-def
"i" #'my/index-nav)
:infix "i"
"" '(:wk "index")
"i" #'my/index-nav
"s" #'my/index-commands-sync
"p" #'my/index-nav-with-select-file)
(defun my/index-export (file)
(interactive (list (read-file-name "File: " "~/logs-sync/data/index.json")))

View file

@ -902,6 +902,9 @@ And keybindings that are available in both =char-mode= and =line-mode=:
(,(kbd "<XF86AudioPause>") . ,(my/app-command "mpc pause"))
(,(kbd "<print>") . ,(my/app-command "flameshot gui"))
;; Input method
(,(kbd "M-\\") . my/toggle-input-method)
;; Switch workspace
(,(kbd "s-q") . my/exwm-switch-to-other-monitor)
(,(kbd "s-w") . exwm-workspace-switch)
@ -942,10 +945,6 @@ A function to apply changes to =exwm-input-global-keys=.
*** App shortcuts
A +transient+ hydra for shortcuts for the most frequent apps.
#+begin_src emacs-lisp
(defun my/run-in-background (command)
(let ((command-parts (split-string command "[ ]+")))
(apply #'call-process `(,(car command-parts) nil 0 nil ,@(cdr command-parts)))))
(defhydra my/exwm-apps-hydra (:color blue :hint nil)
"
^Apps^

View file

@ -268,6 +268,15 @@ By default Emacs and its packages create a lot files in =.emacs.d= and in other
(use-package no-littering
:straight t)
#+end_src
** Helper functions
*** Run command in background
I think I've copied it from somewhere.
#+begin_src emacs-lisp
(defun my/run-in-background (command)
(let ((command-parts (split-string command "[ ]+")))
(apply #'call-process `(,(car command-parts) nil 0 nil ,@(cdr command-parts)))))
#+end_src
** Prevent Emacs from closing
This adds a confirmation to avoid accidental Emacs closing.
@ -961,12 +970,30 @@ References:
(setq default-input-method "russian-computer")
#+end_src
I also want to call =xkb-switch= in EXWM buffers with the same keybindig.
| Guix dependency |
|-----------------|
| xkb-switch |
#+begin_src emacs-lisp
(defun my/toggle-input-method ()
(interactive)
(if (derived-mode-p 'exwm-mode)
(my/run-in-background "xkb-switch -n")
(if (equal (string-trim
(shell-command-to-string "xkb-switch -p"))
"us")
(toggle-input-method)
(my/run-in-background "xkb-switch -s us"))))
#+end_src
=M-x delete-horizontal-space= doesn't feel that useful to me.
#+begin_src emacs-lisp
(general-define-key
:keymaps 'global
"M-\\" #'toggle-input-method)
"M-\\" #'my/toggle-input-method)
#+end_src
*** Other small packages
@ -996,14 +1023,14 @@ Input accented characters.
#+begin_src emacs-lisp
(use-package accent
:straight t
:straight (:host github :repo "SqrtMinusOne/accent")
:init
(general-define-key
:states '(normal)
"gs" #'accent-menu)
"gs" #'accent-company)
(general-define-key
:states '(normal insert)
"M-n" #'accent-menu)
"M-n" #'accent-company)
:commands (accent-menu)
:config
(general-define-key
@ -7522,8 +7549,9 @@ Some initial configuration.
("ll" "ls -la")
("e" "find-file")))
(setq eshell-banner-message "")
(setq eshell-visual-commands
`(,@eshell-visual-commands "jless")))
;; (setq eshell-visual-commands
;; `(,@eshell-visual-commands "jless"))
)
#+end_src
**** UI
@ -11229,18 +11257,9 @@ NAV is a structure as defined by `my/index--nav-get'."
(defun my/index-nav (arg &optional func)
"Navigate the filesystem index.
ARG is the prefix argument. It modifies the behavior of the
command as follows:
- If not in an indexed directory, or in an indexed directory with no
indexed children:
- nil: Select an indexed directory.
- '(4): Select an indexed directory, and select a child indexed
directory if available.
- If in an indexed directory with indexed children (a project):
- nil: Select another indexed directory from the project.
- '(4): Select a top-level indexed directory (the same as nil for
the previous case).
- '(16): The same as '(4) for the previous case.
If ARG is nil, navigate all levels sequentially from the top one.
If ARG is '(4), select another directory from the same level.
FUNC is the function to call with the selected path. It defaults
to `dired' if used interactively."
@ -11249,28 +11268,35 @@ to `dired' if used interactively."
(current-nav (my/index--nav-find-path
nav (expand-file-name default-directory)))
(current-child-navs (alist-get :child-navs current-nav)))
(cond
((or (and (null arg) (null current-child-navs))
(and (equal arg '(4)) current-child-navs))
(funcall
func
(my/index--nav-prompt nav)))
((or (and (equal arg '(4)) (null current-child-navs))
(and (equal arg '(16)) current-child-navs))
(let ((selected (my/index--nav-find-path
nav
(my/index--nav-prompt nav))))
(if-let (child-navs (alist-get :child-navs selected))
(funcall func (my/index--nav-prompt child-navs))
(funcall func (alist-get :path selected)))))
((and (null arg) current-child-navs)
(funcall func (my/index--nav-prompt current-child-navs))))))
(cond ((null arg)
(let ((selected (my/index--nav-find-path
nav
(my/index--nav-prompt nav))))
(if-let (child-navs (alist-get :child-navs selected))
(funcall func (my/index--nav-prompt child-navs))
(funcall func (alist-get :path selected)))))
((and (equal arg '(4)) current-child-navs)
(funcall func (my/index--nav-prompt current-child-navs)))
((and (equal arg '(4)) (null current-child-navs))
(funcall func (my/index--nav-prompt nav))))))
#+end_src
Finally, something that I can bind to a key.
#+begin_src emacs-lisp
(defun my/index-nav-with-select-file (arg)
(interactive (list current-prefix-arg))
(my/index-nav
arg
(lambda (dir)
(let ((default-directory dir))
(projectile-find-file)))))
(my-leader-def
"i" #'my/index-nav)
:infix "i"
"" '(:wk "index")
"i" #'my/index-nav
"s" #'my/index-commands-sync
"p" #'my/index-nav-with-select-file)
#+end_src
*** Export tree
I also need the tree to use in my =sqrt-data=, so let's export this to JSON.