From 677a6cb2f63db7048ab85fee5cc81a1f7ba20813 Mon Sep 17 00:00:00 2001 From: Pierre Neidhardt Date: Mon, 22 May 2017 16:24:25 +0200 Subject: [PATCH] Emacs: Replace most mapc/mapcar by dolist --- .emacs.d/init.el | 12 +++++------- .emacs.d/lisp/main.el | 16 ++++------------ .emacs.d/lisp/mode-cc.el | 6 ++---- .emacs.d/lisp/mode-eshell.el | 22 ++++++++++------------ .emacs.d/lisp/mode-latex.el | 6 ++---- .emacs.d/lisp/mode-tex.el | 35 ++++++++++++++--------------------- .emacs.d/lisp/visual.el | 32 ++++++++++++++------------------ 7 files changed, 51 insertions(+), 78 deletions(-) diff --git a/.emacs.d/init.el b/.emacs.d/init.el index 3b1675a3..68d7ddcc 100644 --- a/.emacs.d/init.el +++ b/.emacs.d/init.el @@ -215,13 +215,11 @@ To view where the bindings are set in your config files, lookup ; (setq pdf-viewer "evince") ; (setq pdf-viewer-args nil) ; -; (mapcar -; (lambda (mode-hook) -; (add-hook mode-hook (lambda () (run-hooks 'prog-mode-hook)))) -; '(asm-mode-hook awk-mode-hook c++-mode-hook c-mode-hook -; emacs-lisp-mode-hook lisp-mode-hook lua-mode-hook -; makefile-mode-hook octave-mode-hook perl-mode-hook -; python-mode-hook scheme-mode-hook sh-mode-hook)) +; (dolist (hook '(asm-mode-hook awk-mode-hook c++-mode-hook c-mode-hook +; emacs-lisp-mode-hook lisp-mode-hook lua-mode-hook +; makefile-mode-hook octave-mode-hook perl-mode-hook +; python-mode-hook scheme-mode-hook sh-mode-hook)) +; (add-hook hook (lambda () (run-hooks 'prog-mode-hook)))) ; ; (defun comment-line... ;; From emacs 25 ; diff --git a/.emacs.d/lisp/main.el b/.emacs.d/lisp/main.el index fd9305c2..15b60efd 100644 --- a/.emacs.d/lisp/main.el +++ b/.emacs.d/lisp/main.el @@ -85,24 +85,16 @@ (setq-default indent-tabs-mode t) ;; Lisp should not use tabs. -(mapc - (lambda (hook) - (add-hook - hook - (lambda () - (setq indent-tabs-mode nil)))) - '(lisp-mode-hook emacs-lisp-mode-hook)) +(dolist (hook '(lisp-mode-hook emacs-lisp-mode-hook)) + (add-hook hook (lambda () (setq indent-tabs-mode nil)))) (add-hook 'emacs-lisp-mode-hook - (lambda () - (local-set-key (kbd "M-.") 'find-symbol-at-point))) + (lambda () (local-set-key (kbd "M-.") 'find-symbol-at-point))) (add-hook 'change-log-mode-hook - (lambda () - (setq tab-width 2) - (setq left-margin 2))) + (lambda () (setq tab-width 2 left-margin 2))) ;; This needs to be set globally since they are defined as local variable and ;; Emacs does not know how to set an alias on a local variable. diff --git a/.emacs.d/lisp/mode-cc.el b/.emacs.d/lisp/mode-cc.el index 2c2bdff0..fdd6aa10 100644 --- a/.emacs.d/lisp/mode-cc.el +++ b/.emacs.d/lisp/mode-cc.el @@ -123,16 +123,14 @@ restored." ;; function. Since cc modes belong to prog-mode, each hook is called another ;; time at the end of the initialization. No big deal since we only set some ;; variables. -(mapc - (lambda (mode-hook) +(dolist (hook '(c-mode-hook c++-mode-hook)) (add-hook-and-eval - mode-hook + hook (lambda () (c-set-style "ambrevar") ;; We override existing values. (when (require 'company nil t) (company-mode)) (cc-set-compiler)))) - '(c-mode-hook c++-mode-hook)) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Skeletons diff --git a/.emacs.d/lisp/mode-eshell.el b/.emacs.d/lisp/mode-eshell.el index a65452ed..6140a77a 100644 --- a/.emacs.d/lisp/mode-eshell.el +++ b/.emacs.d/lisp/mode-eshell.el @@ -32,18 +32,16 @@ ;; eshell/alias is too slow as it reads and write the file on each definition. (with-eval-after-load 'em-alias (eshell-read-aliases-list) - (mapc - (lambda (alias) - (add-to-list 'eshell-command-aliases-list alias)) - '(("ls" "ls -F $*") - ("l" "ls -1 $*") - ("la" "ls -lAh $*") - ("ll" "ls -lh $*") - ("grep" "grep --color=auto") - ("mkdir" "mkdir -p $*") - ("mkcd" "mkdir -p $* && cd $1") - ("emacs" "find-file $1") - ("em" "find-file $1"))) + (dolist (alias '(("ls" "ls -F $*") + ("l" "ls -1 $*") + ("la" "ls -lAh $*") + ("ll" "ls -lh $*") + ("grep" "grep --color=auto") + ("mkdir" "mkdir -p $*") + ("mkcd" "mkdir -p $* && cd $1") + ("emacs" "find-file $1") + ("em" "find-file $1"))) + (add-to-list 'eshell-command-aliases-list alias)) (eshell-write-aliases-list)) (provide 'mode-eshell) diff --git a/.emacs.d/lisp/mode-latex.el b/.emacs.d/lisp/mode-latex.el index 536f3cbf..f2d7b2d5 100644 --- a/.emacs.d/lisp/mode-latex.el +++ b/.emacs.d/lisp/mode-latex.el @@ -65,10 +65,8 @@ (setq latex-block-default "itemize") (setq latex-block-names '("listing" "align" "align*" "Bmatrix" "Vmatrix" "bmatrix" "matrix" "pmatrix" "smallmatrix" "vmatrix")) -(mapc - (lambda (latex-block) - (add-to-list 'latex-block-body-alist `(,latex-block nil '(delete-horizontal-space t) _))) - '("listing" "verbatim" "verbatim*")) +(dolist (block '("listing" "verbatim" "verbatim*")) + (add-to-list 'latex-block-body-alist `(,block nil '(delete-horizontal-space t) _))) (add-hook-and-eval 'latex-mode-hook diff --git a/.emacs.d/lisp/mode-tex.el b/.emacs.d/lisp/mode-tex.el index 289b5e9c..f441f1dc 100644 --- a/.emacs.d/lisp/mode-tex.el +++ b/.emacs.d/lisp/mode-tex.el @@ -47,8 +47,7 @@ (interactive) (hack-local-variables) (let* (;; Master file. - (local-master - (if tex-masterfile tex-masterfile (if buffer-file-name buffer-file-name (error "Buffer has no file name")))) + (local-master (or tex-masterfile buffer-file-name (error "Buffer has no file name"))) (dirname (file-name-directory local-master)) (basename (file-name-sans-extension (file-name-nondirectory local-master))) ;; Note: makeindex fails with absolute file names, we need relative names. @@ -66,32 +65,26 @@ " " (shell-quote-argument basename))))) (defun tex-clean () - "Remove all TeX temporary files. This command should be safe, -but there is no warranty." + "Remove all TeX temporary files. +This command should be safe, but there is no warranty." (interactive) (hack-local-variables) - (let ((master (concat - (if tex-masterfile - (file-name-sans-extension tex-masterfile) - (file-name-sans-extension buffer-file-name)) - "."))) - (mapc - ;; Delete file if it exists. - (lambda (argfile) - (when (and (file-exists-p argfile) (file-writable-p argfile)) - (delete-file argfile) - (message "[%s] deleted." argfile))) - (mapc - ;; Concat file name with extensions. - (lambda (arg) (concat master arg)) - tex-extension-list)))) + (let ((master (file-name-sans-extension (or tex-masterfile buffer-file-name)))) + (dolist (file (mapcar + ;; Concat file name with extensions. + (lambda (arg) (concat master "." arg)) + tex-extension-list)) + ;; Delete file if it exists. + (when (and (file-exists-p file) (file-writable-p file)) + (delete-file file) + (message "Deleted %S." file))))) (defun tex-pdf-compress () "Use `tex-masterfile' variable as default value for `pdf-compress'." (interactive) (require 'tool-pdf) (hack-local-variables) - (let ((local-master (if tex-masterfile tex-masterfile buffer-file-name))) + (let ((local-master (or tex-masterfile buffer-file-name))) (pdf-compress local-master))) (defun tex-pdf-view () @@ -99,7 +92,7 @@ but there is no warranty." (interactive) (require 'tool-pdf) (hack-local-variables) - (let ((local-master (if tex-masterfile tex-masterfile buffer-file-name))) + (let ((local-master (or tex-masterfile buffer-file-name))) (pdf-view local-master))) (defun tex-toggle-escape-char () diff --git a/.emacs.d/lisp/visual.el b/.emacs.d/lisp/visual.el index 86a2c4b7..4e6d03b7 100644 --- a/.emacs.d/lisp/visual.el +++ b/.emacs.d/lisp/visual.el @@ -83,15 +83,13 @@ (set-face-foreground 'compilation-line-number "cyan"))) ;; C additional keywords. -(mapc - (lambda (mode) +(dolist (mode '(c-mode c++-mode)) (font-lock-add-keywords mode '(("\\<\\(and\\|or\\|not\\)\\>" . font-lock-keyword-face) ;; Functions. ("\\<\\(\\sw+\\)(" 1 'font-lock-function-name-face) ("\\<\\(\\sw+\\)<\\sw+>(" 1 'font-lock-function-name-face)))) - '(c-mode c++-mode)) ;; Ediff (add-hook @@ -155,21 +153,19 @@ ;; Key notes highlighting. We need to apply it to the mode hook since ;; font-lock-add-keywords has no inheritance support. (set-face-foreground 'font-lock-warning-face "DarkOrange") -(mapc - (lambda (mode-hook) - (add-hook - mode-hook - (lambda () (interactive) - (font-lock-add-keywords - nil - ;; See https://en.wikipedia.org/wiki/Comment_(computer_programming)#Tags. - '(("\\<\\(FIXME\\(([^)]+)\\)?\\):" 1 font-lock-warning-face prepend) - ("\\<\\(TODO\\(([^)]+)\\)?\\):" 1 font-lock-warning-face prepend) - ("\\<\\(UNDONE\\):" 1 font-lock-warning-face prepend) - ("\\<\\(UX\\):" 1 font-lock-warning-face prepend) - ("\\<\\(WARNING\\):" 1 font-lock-warning-face prepend) - ("\\<\\(XXX\\):" 1 font-lock-warning-face prepend)))))) - '(prog-mode-hook tex-mode-hook texinfo-mode-hook)) +(dolist (hook '(prog-mode-hook tex-mode-hook texinfo-mode-hook)) + (add-hook + hook + (lambda () (interactive) + (font-lock-add-keywords + nil + ;; See https://en.wikipedia.org/wiki/Comment_(computer_programming)#Tags. + '(("\\<\\(FIXME\\(([^)]+)\\)?\\):" 1 font-lock-warning-face prepend) + ("\\<\\(TODO\\(([^)]+)\\)?\\):" 1 font-lock-warning-face prepend) + ("\\<\\(UNDONE\\):" 1 font-lock-warning-face prepend) + ("\\<\\(UX\\):" 1 font-lock-warning-face prepend) + ("\\<\\(WARNING\\):" 1 font-lock-warning-face prepend) + ("\\<\\(XXX\\):" 1 font-lock-warning-face prepend)))))) ;; Man pages (add-hook