Emacs: Replace most mapc/mapcar by dolist

master
Pierre Neidhardt 2017-05-22 16:24:25 +02:00
parent 581d7799d5
commit 677a6cb2f6
7 changed files with 51 additions and 78 deletions

View File

@ -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
;

View File

@ -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.

View File

@ -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

View File

@ -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)

View File

@ -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

View File

@ -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 ()

View File

@ -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