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,34 +904,40 @@
- 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-text
#+BEGIN_SRC emacs-lisp
(lambda (x)
(format "awful.key({%s},\"%s\",%s,\n\t{description=\"%s\",group=\"%s\"})"
(nth 1 x) (nth 0 x)
(cond
((string= "yes" (nth 2 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)))
#+END_SRC
#+NAME: gen-sc-glob #+NAME: gen-sc-glob
#+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) (seq-filter (lambda (x)
(if (string= "yes" (nth 2 x)) (or (not (nth 6 x))
(format "function() %s end" (nth 3 x)) (string= "no" (nth 6 x))))
(nth 3 x)) table)
(nth 4 x) (nth 5 x))) ",\n")
(seq-filter (lambda (x)
(not (string= "yes" (nth 6 x))))
table)
",\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) (seq-filter (lambda (x)
(if (string= "yes" (nth 2 x)) (string= "yes" (nth 6 x)))
(format "function(c) %s end" (nth 3 x)) table)
(nth 3 x)) ",\n")
(nth 4 x) (nth 5 x)))
(seq-filter (lambda (x)
(string= "yes" (nth 6 x)))
table)
",\n")
#+END_SRC #+END_SRC
#+NAME: sc-tag-num-gen #+NAME: sc-tag-num-gen
@ -940,11 +946,13 @@
(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)
(nth 1 line) (+ j 9) (nth 2 line) j (nth 3 line) j (nth 4 line))) (format
input "awful.key({%s},\"#%d\",function() %s%d) end,\n\t{description=\"%s%d\",tag=\"%s\"})"
",\n") (nth 1 line) (+ j 9) (nth 2 line) j (nth 3 line) j (nth 4 line)))
input
",\n")
result)))) result))))
(mapconcat (lambda (x) x) (mapconcat (lambda (x) x)
result result