[StumpWM] Update some elisp, more natural keybind declaration
If characters such as `«` or `»` are used, they get replaced by their complete name. See table `tbl-char-to-name`.
This commit is contained in:
parent
4a6fbf3264
commit
d63da4af42
@ -1253,6 +1253,34 @@ following characters:
|
|||||||
So if you see any weird keybind involving these characters, this is
|
So if you see any weird keybind involving these characters, this is
|
||||||
because of my layout.
|
because of my layout.
|
||||||
|
|
||||||
|
Something a bit annoying though is Lisp doesn’t know some characters
|
||||||
|
by their actual name, rather by another one that I find too long and
|
||||||
|
too bothersome to remember. So here’s a list, if you see any of the
|
||||||
|
characters on the left column in my config, with some org-mode magic,
|
||||||
|
my actual config will use their name as specified in the right column.
|
||||||
|
Actually, you even saw some if not all in the previous table.
|
||||||
|
#+name: tbl-char-to-name
|
||||||
|
| Character | Name |
|
||||||
|
|-----------+------------------|
|
||||||
|
| ~«~ | ~guillemotleft~ |
|
||||||
|
| ~»~ | ~guillemotright~ |
|
||||||
|
|
||||||
|
#+name: char-to-name
|
||||||
|
#+header: :exports none :noweb yes :results verbatim
|
||||||
|
#+begin_src emacs-lisp :var table=tbl-char-to-name
|
||||||
|
(defun my/stumpwm-char-to-name (char)
|
||||||
|
(let* ((table (mapcar (lambda (entry)
|
||||||
|
(cons (replace-regexp-in-string "^~" "" (car entry))
|
||||||
|
(replace-regexp-in-string "^~" "" (cadr entry))))
|
||||||
|
table))
|
||||||
|
(table (mapcar (lambda (entry)
|
||||||
|
(cons (replace-regexp-in-string "~$" "" (car entry))
|
||||||
|
(replace-regexp-in-string "~$" "" (cdr entry))))
|
||||||
|
table)))
|
||||||
|
(or (cdr (assoc char table))
|
||||||
|
char)))
|
||||||
|
#+end_src
|
||||||
|
|
||||||
** Applications
|
** Applications
|
||||||
:PROPERTIES:
|
:PROPERTIES:
|
||||||
:CUSTOM_ID: Keybinds-Applications-2t512k00w5j0
|
:CUSTOM_ID: Keybinds-Applications-2t512k00w5j0
|
||||||
@ -1725,20 +1753,20 @@ Then, let’s declare a keymap for our media controls.
|
|||||||
|
|
||||||
#+name: media-management
|
#+name: media-management
|
||||||
#+caption: ~*my-media-keymap*~
|
#+caption: ~*my-media-keymap*~
|
||||||
| Keychord | Function |
|
| Keychord | Function |
|
||||||
|----------------+-----------------------------|
|
|----------+-----------------------------|
|
||||||
| ~.~ | ~media-interactive~ |
|
| ~.~ | ~media-interactive~ |
|
||||||
| ~guillemotleft~ | ~mpd-prev~ |
|
| ~«~ | ~mpd-prev~ |
|
||||||
| ~guillemotright~ | ~mpd-next~ |
|
| ~»~ | ~mpd-next~ |
|
||||||
| ~a~ | ~'*my-mpd-add-map*~ |
|
| ~a~ | ~'*my-mpd-add-map*~ |
|
||||||
| ~b~ | ~'*my-mpd-browse-map*~ |
|
| ~b~ | ~'*my-mpd-browse-map*~ |
|
||||||
| ~c~ | ~mpd-clear~ |
|
| ~c~ | ~mpd-clear~ |
|
||||||
| ~m~ | ~mpc-interactive~ |
|
| ~m~ | ~mpc-interactive~ |
|
||||||
| ~p~ | ~mpd-toggle-pause~ |
|
| ~p~ | ~mpd-toggle-pause~ |
|
||||||
| ~s~ | ~mpd-stop~ |
|
| ~s~ | ~mpd-stop~ |
|
||||||
| ~u~ | ~mpd-update~ |
|
| ~u~ | ~mpd-update~ |
|
||||||
| ~N~ | ~term ncmpcpp -q~ |
|
| ~N~ | ~term ncmpcpp -q~ |
|
||||||
| ~v~ | ~term ncmpcpp -qs visualizer~ |
|
| ~v~ | ~term ncmpcpp -qs visualizer~ |
|
||||||
|
|
||||||
Let’s translate this table in CommonLisp:
|
Let’s translate this table in CommonLisp:
|
||||||
#+begin_src lisp
|
#+begin_src lisp
|
||||||
@ -1826,12 +1854,15 @@ games and the bépo layout most of the time. I’ll use the command
|
|||||||
:END:
|
:END:
|
||||||
|
|
||||||
#+name: keybinds-gen
|
#+name: keybinds-gen
|
||||||
#+begin_src emacs-lisp :var map="m" keybinds=frames-float
|
#+header: :wrap "src lisp :exports none" :exports none :noweb yes
|
||||||
|
#+begin_src emacs-lisp :var map="m" keybinds=media-management :var table=tbl-char-to-name
|
||||||
|
<<char-to-name>>
|
||||||
(mapconcat (lambda (keybind)
|
(mapconcat (lambda (keybind)
|
||||||
(format "%s" (let ((key (let ((s (car keybind)))
|
(format "%s" (let* ((key (let ((s (car keybind)))
|
||||||
(substring-no-properties s 1 (1- (length s)))))
|
(substring-no-properties s 1 (1- (length s)))))
|
||||||
(function (let ((s (cadr keybind)))
|
(function (let ((s (cadr keybind)))
|
||||||
(substring-no-properties s 1 (1- (length s))))))
|
(substring-no-properties s 1 (1- (length s)))))
|
||||||
|
(key (my/stumpwm-char-to-name key)))
|
||||||
`(define-key ,map
|
`(define-key ,map
|
||||||
(kbd ,(format "\"%s\"" key))
|
(kbd ,(format "\"%s\"" key))
|
||||||
,(if (string-prefix-p "'" function t)
|
,(if (string-prefix-p "'" function t)
|
||||||
@ -1841,6 +1872,22 @@ games and the bépo layout most of the time. I’ll use the command
|
|||||||
"\n")
|
"\n")
|
||||||
#+end_src
|
#+end_src
|
||||||
|
|
||||||
|
#+RESULTS[a20994f97465549466dd676b4b452593194e0495]: keybinds-gen
|
||||||
|
#+begin_src lisp :exports none
|
||||||
|
(define-key m (kbd ".") "media-interactive")
|
||||||
|
(define-key m (kbd "guillemotleft") "mpd-prev")
|
||||||
|
(define-key m (kbd "guillemotright") "mpd-next")
|
||||||
|
(define-key m (kbd "a") '*my-mpd-add-map*)
|
||||||
|
(define-key m (kbd "b") '*my-mpd-browse-map*)
|
||||||
|
(define-key m (kbd "c") "mpd-clear")
|
||||||
|
(define-key m (kbd "m") "mpc-interactive")
|
||||||
|
(define-key m (kbd "p") "mpd-toggle-pause")
|
||||||
|
(define-key m (kbd "s") "mpd-stop")
|
||||||
|
(define-key m (kbd "u") "mpd-update")
|
||||||
|
(define-key m (kbd "N") "term ncmpcpp -q")
|
||||||
|
(define-key m (kbd "v") "term ncmpcpp -qs visualizer")
|
||||||
|
#+end_src
|
||||||
|
|
||||||
#+name: interactive-gen
|
#+name: interactive-gen
|
||||||
#+begin_src emacs-lisp :var name="inter" keys=inter-mpc
|
#+begin_src emacs-lisp :var name="inter" keys=inter-mpc
|
||||||
(format "%s"
|
(format "%s"
|
||||||
@ -1863,7 +1910,7 @@ games and the bépo layout most of the time. I’ll use the command
|
|||||||
#+end_src
|
#+end_src
|
||||||
|
|
||||||
#+name: num-to-char
|
#+name: num-to-char
|
||||||
#+begin_src emacs-lisp :var table=number-to-char-table num=0
|
#+begin_src emacs-lisp :var table=number-to-char-table num=2
|
||||||
(let ((char (replace-regexp-in-string (regexp-quote "~")
|
(let ((char (replace-regexp-in-string (regexp-quote "~")
|
||||||
""
|
""
|
||||||
(let* ((row (assoc num table))
|
(let* ((row (assoc num table))
|
||||||
@ -1877,5 +1924,5 @@ games and the bépo layout most of the time. I’ll use the command
|
|||||||
char))
|
char))
|
||||||
#+end_src
|
#+end_src
|
||||||
|
|
||||||
#+RESULTS[6934c27c10c3f968f70b0112d4639298e519fe61]: num-to-char
|
#+RESULTS[0c35d70ec5195a6f24fdaa1f5847c1bda7ae18be]: num-to-char
|
||||||
: *
|
: guillemotleft
|
||||||
|
Loading…
Reference in New Issue
Block a user