Better use of litterate programming

This commit is contained in:
Lucien Cartier-Tilet 2020-04-11 00:42:30 +02:00
parent 7dc74ae0ac
commit fe5e3de04c
Signed by: phundrak
GPG Key ID: BD7789E705CB8DCA

View File

@ -904,30 +904,36 @@
- Clientkey :: whether this should be a global shortcut or a shortcut only - Clientkey :: whether this should be a global shortcut or a shortcut only
aimed at clients (value is ~yes~ or ~no~) aimed at clients (value is ~yes~ or ~no~)
#+NAME: gen-sc-glob #+NAME: gen-sc-text
#+BEGIN_SRC emacs-lisp :var table=sc-client #+BEGIN_SRC emacs-lisp
(mapconcat (lambda (x) (lambda (x)
(format "awful.key({%s},\"%s\",%s,\n\t{description=\"%s\",group=\"%s\"})" (format "awful.key({%s},\"%s\",%s,\n\t{description=\"%s\",group=\"%s\"})"
(nth 1 x) (nth 0 x) (nth 1 x) (nth 0 x)
(if (string= "yes" (nth 2 x)) (cond
(format "function() %s end" (nth 3 x)) ((string= "yes" (nth 2 x))
(nth 3 x)) (format "function() %s end" (nth 3 x)))
((string= "shell" (nth 2 x))
(format "awful.spawn.with_shell(\"%s\")" (nth 3 x)))
(t (nth 3 x)))
(nth 4 x) (nth 5 x))) (nth 4 x) (nth 5 x)))
#+END_SRC
#+NAME: gen-sc-glob
#+BEGIN_SRC emacs-lisp :var table=sc-client
(mapconcat
<<gen-sc-text>>
(seq-filter (lambda (x) (seq-filter (lambda (x)
(not (string= "yes" (nth 6 x)))) (or (not (nth 6 x))
(string= "no" (nth 6 x))))
table) table)
",\n") ",\n")
#+END_SRC #+END_SRC
#+NAME: gen-sc-client #+NAME: gen-sc-client
#+BEGIN_SRC emacs-lisp :var table=sc-client #+BEGIN_SRC emacs-lisp :var table=sc-client
(mapconcat (lambda (x) (mapconcat
(format "awful.key({%s},\"%s\",%s,\n\t{description=\"%s\",group=\"%s\"})" <<gen-sc-text>>
(nth 1 x) (nth 0 x)
(if (string= "yes" (nth 2 x))
(format "function(c) %s end" (nth 3 x))
(nth 3 x))
(nth 4 x) (nth 5 x)))
(seq-filter (lambda (x) (seq-filter (lambda (x)
(string= "yes" (nth 6 x))) (string= "yes" (nth 6 x)))
table) table)
@ -940,8 +946,10 @@
(dotimes (i 10 result) (dotimes (i 10 result)
(let* ((j (+ 1 i))) (let* ((j (+ 1 i)))
(setq result (setq result
(cons (mapconcat (lambda (line) (cons (mapconcat
(format "awful.key({%s},\"#%d\",function() %s%d) end,\n\t{description=\"%s%d\",tag=\"%s\"})" (lambda (line)
(format
"awful.key({%s},\"#%d\",function() %s%d) end,\n\t{description=\"%s%d\",tag=\"%s\"})"
(nth 1 line) (+ j 9) (nth 2 line) j (nth 3 line) j (nth 4 line))) (nth 1 line) (+ j 9) (nth 2 line) j (nth 3 line) j (nth 4 line)))
input input
",\n") ",\n")