Emacs: Lint most of the config

master
Pierre Neidhardt 2017-05-24 00:27:02 +02:00
parent de36a4b943
commit 7e44e34761
11 changed files with 52 additions and 48 deletions

View File

@ -13,7 +13,7 @@
; (setq start (point-min) end (point-max))) ; (setq start (point-min) end (point-max)))
; ;
;; If several commands act on region and the region size/pos is susceptible to change: ;; If several commands act on region and the region size/pos is susceptible to change:
; (save-excursion ; (save-mark-and-excursion
; (unless mark-active ; (unless mark-active
; (mark-whole-buffer)) ; (mark-whole-buffer))
;; Then call (region-beginning) and (region-end) ;; Then call (region-beginning) and (region-end)
@ -39,7 +39,7 @@ while `run-mode-hooks' is running."
(apply 'call-process program nil t nil args)))) (apply 'call-process program nil t nil args))))
(defun count-occurences (regex string) (defun count-occurences (regex string)
"Return number of times regex occurs in string. "Return number of times REGEX occurs in STRING.
If you want to operate on buffer, use `how-many' instead." If you want to operate on buffer, use `how-many' instead."
(let ((start 0) (matches 0)) (let ((start 0) (matches 0))
(while (string-match regex string start) (while (string-match regex string start)
@ -74,7 +74,7 @@ there's a region, all lines that region covers will be duplicated."
(define-key mickey-minor-mode-map (kbd "C-x M-d") 'duplicate) (define-key mickey-minor-mode-map (kbd "C-x M-d") 'duplicate)
(defun emacs-process-p (pid) (defun emacs-process-p (pid)
"If pid is the process ID of an emacs process, return t, else nil. "If PID is the process ID of an Emacs process, return t, else nil.
Also returns nil if pid is nil." Also returns nil if pid is nil."
(when pid (when pid
(let ((attributes (process-attributes pid)) (cmd)) (let ((attributes (process-attributes pid)) (cmd))
@ -86,15 +86,15 @@ Also returns nil if pid is nil."
(defun escape-region (&optional regex to-string) (defun escape-region (&optional regex to-string)
"Escape double-quotes and backslashes. "Escape double-quotes and backslashes.
This is useful for writing Elisp strings containing those This is useful for writing Elisp strings containing those
characters. You can control the regex replacement with the two characters. The optional parameters let you control the replacement of REGEX for
optional parameters." TO-STRING."
(interactive) (interactive)
(unless regex (setq regex "\\([\"\\\\]\\)")) (unless regex (setq regex "\\([\"\\\\]\\)"))
(unless to-string (setq to-string "\\\\\\1")) (unless to-string (setq to-string "\\\\\\1"))
(save-excursion (save-excursion
(while (re-search-forward (while (re-search-forward
regex regex
(if (not mark-active) (point-max) (region-end)) (if mark-active (region-end) (point-max))
t) t)
(replace-match to-string)))) (replace-match to-string))))
@ -129,7 +129,8 @@ optional parameters."
;; above comment. ;; above comment.
;; TODO: Fix reported to http://debbugs.gnu.org/cgi/bugreport.cgi?bug=20663. ;; TODO: Fix reported to http://debbugs.gnu.org/cgi/bugreport.cgi?bug=20663.
(defun forward-page (&optional count) (defun forward-page (&optional count)
"Move forward to page boundary. With arg, repeat, or go back if negative. "Move forward to page boundary.
With prefix or COUNT, repeat, or go back if negative.
A page boundary is any line whose beginning matches the regexp A page boundary is any line whose beginning matches the regexp
`page-delimiter'." `page-delimiter'."
(interactive "p") (interactive "p")
@ -197,7 +198,8 @@ it appears in the minibuffer prompt."
(insert filename)))) (insert filename))))
(defun load-external (ext feature &optional mode default) (defun load-external (ext feature &optional mode default)
"Add the EXT regex to `auto-mode-alist' such that it loads the "Load FEATURE with EXT.
Add the EXT regex to `auto-mode-alist' such that it loads the
associated symbol FEATURE. If FEATURE has not the same name as associated symbol FEATURE. If FEATURE has not the same name as
the mode, you should provide the real mode name in symbol MODE. the mode, you should provide the real mode name in symbol MODE.
If MODE is nil or unspecified, FEATURE is used as the mode name. If MODE is nil or unspecified, FEATURE is used as the mode name.
@ -213,14 +215,15 @@ fallback to the mode provided in symbol DEFAULT."
(,local-mode) (,local-mode)
,(if (null default) ,(if (null default)
`(warn "Could not load %s, fallback to %s" `(warn "Could not load %s, fallback to %s"
(symbol-name ',feature) (symbol-name ',default-major-mode)) (symbol-name ',feature) (symbol-name ',major-mode))
`(progn `(progn
(,default) (,default)
(warn "Could not load %s, fallback to %s" (warn "Could not load %s, fallback to %s"
(symbol-name ',feature) (symbol-name ',default)))))))))) (symbol-name ',feature) (symbol-name ',default))))))))))
(defun mark-word-from-beginning (&optional arg allow-extend) (defun mark-word-from-beginning (&optional arg allow-extend)
"Set the point at the beginning of the word and call `mark-word'." "Set the point at the beginning of the word and call `mark-word'.
ARG and ALLOW-EXTEND are the same."
(interactive "P\np") (interactive "P\np")
(cond ((and allow-extend (cond ((and allow-extend
(or (and (eq last-command this-command) (mark t)) (or (and (eq last-command this-command) (mark t))
@ -240,17 +243,18 @@ If this is a window with its right edge being the edge of the
screen, enlarge the window horizontally. If this is a window with screen, enlarge the window horizontally. If this is a window with
its left edge being the edge of the screen, shrink the window its left edge being the edge of the screen, shrink the window
horizontally. Otherwise, default to enlarging horizontally.\n horizontally. Otherwise, default to enlarging horizontally.\n
Enlarge/Shrink by ARG columns, or 5 if arg is nil." Enlarge/Shrink by ARG columns, or 5 if ARG is nil."
(interactive "P") (interactive "P")
(if (= (count-windows) 2) (if (= (count-windows) 2)
(move-border-left-or-right arg t))) (move-border-left-or-right arg t)))
(define-key mickey-minor-mode-map (kbd "M-(") 'move-border-left) (define-key mickey-minor-mode-map (kbd "M-(") 'move-border-left)
(defun move-border-left-or-right (arg dir-left) (defun move-border-left-or-right (arg dir-left)
"Wrapper around move-border-left and move-border-right. "Wrapper around move-border-left and move-border-right.
If DIR is t, then move left, otherwise move right." ARG is the number of columns to move.
If DIR-LEFT is t, then move left, otherwise move right."
(interactive) (interactive)
(if (null arg) (setq arg 5)) (unless arg (setq arg 5))
(let ((left-edge (= (car (window-edges)) 0))) (let ((left-edge (= (car (window-edges)) 0)))
(if (or (if (or
(and left-edge dir-left) (and left-edge dir-left)
@ -293,7 +297,7 @@ If ACTIVATE is non-nil, enable, disable otherwise. Interactively,
activate unless called with \\[universal-argument].\n\nThis adds activate unless called with \\[universal-argument].\n\nThis adds
page-number/page-count to mode line. It will only display if page-number/page-count to mode line. It will only display if
there is more than one page. A page is delimited by there is more than one page. A page is delimited by
page-delimiter.\n page-delimiter.\n
WARNING: this may slow down editing on big files." WARNING: this may slow down editing on big files."
(interactive (list (not (equal current-prefix-arg '(4))))) (interactive (list (not (equal current-prefix-arg '(4)))))
(setq mode-line-format (setq mode-line-format
@ -334,8 +338,9 @@ WARNING: this may slow down editing on big files."
(message "File '%s' successfully renamed to '%s'" name (file-name-nondirectory new-name)))))))) (message "File '%s' successfully renamed to '%s'" name (file-name-nondirectory new-name))))))))
(defun sanitize () (defun sanitize ()
"(Un)tabifies according to `indent-tabs-mode', indents and deletes trailing whitespace. "(Un)tabify, indent and delete trailing whitespace.
Works on buffer or region. Requires `tabify-leading'." Tabify if `indent-tabs-mode' is true, otherwise use spaces.
Work on buffer or region. Require `tabify-leading'."
(interactive) (interactive)
(let (start end) (let (start end)
(if mark-active (if mark-active
@ -367,10 +372,11 @@ Hook function for skeletons."
(mapcar 'copy-marker (reverse skeleton-positions)))) (mapcar 'copy-marker (reverse skeleton-positions))))
(defvar skeleton-markers nil (defvar skeleton-markers nil
"Markers for locations saved in skeleton-positions.") "Markers for locations saved in `skeleton-positions'.")
(defun skeleton-next-position (&optional reverse) (defun skeleton-next-position (&optional reverse)
"Skeleton movements through placeholders." "Move to next skeleton placeholder.
If REVERSE it t, move to previes placeholder."
(interactive "P") (interactive "P")
(let ((positions (mapcar 'marker-position skeleton-markers)) (let ((positions (mapcar 'marker-position skeleton-markers))
(comp (if reverse '< '<=)) (comp (if reverse '< '<=))
@ -392,7 +398,7 @@ Do not fold case with \\[universal-argument] or non-nil ARG."
(interactive "P") (interactive "P")
;; We use save-excursion here because the region boundaries change during ;; We use save-excursion here because the region boundaries change during
;; execution, so it's more convenient to track them with region functions. ;; execution, so it's more convenient to track them with region functions.
(save-excursion (save-mark-and-excursion
(unless mark-active (unless mark-active
(mark-whole-buffer)) (mark-whole-buffer))
(let ((sort-fold-case (if arg nil t))) (let ((sort-fold-case (if arg nil t)))
@ -448,7 +454,7 @@ Run it in each window you want to 'freeze', i.e. prevent Emacs
from acting on it." from acting on it."
(interactive) (interactive)
(message (message
(if (let (window (get-buffer-window (current-buffer))) (if (let ((window (get-buffer-window (current-buffer))))
(set-window-dedicated-p window (set-window-dedicated-p window
(not (window-dedicated-p window)))) (not (window-dedicated-p window))))
"Window '%s' is dedicated" "Window '%s' is dedicated"

View File

@ -37,7 +37,7 @@
; (setq version-control t) ; (setq version-control t)
;; Default mode ;; Default mode
(setq default-major-mode 'text-mode) (setq-default major-mode 'text-mode)
;; Disable suspend key since it is useless on Emacs server. ;; Disable suspend key since it is useless on Emacs server.
(global-unset-key (kbd "C-z")) (global-unset-key (kbd "C-z"))

View File

@ -75,7 +75,7 @@ restored."
(if (/= status 0) (if (/= status 0)
(error "error running uncrustify") (error "error running uncrustify")
(delete-region start end) (delete-region start end)
(insert-buffer formatbuf) (insert-buffer-substring formatbuf)
(kill-buffer formatbuf)))) (kill-buffer formatbuf))))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

View File

@ -15,17 +15,14 @@
is executed. If `graphviz-dot-save-before-view' is set, the current is executed. If `graphviz-dot-save-before-view' is set, the current
buffer is saved before the command is executed." buffer is saved before the command is executed."
(interactive) (interactive)
(let ((cmd (if graphviz-dot-view-edit-command (let* ((default-cmd (format graphviz-dot-view-command
(read-from-minibuffer (concat (file-name-sans-extension buffer-file-name)
"View command: " "." graphviz-dot-view-extension)))
(format graphviz-dot-view-command (cmd (if graphviz-dot-view-edit-command
(concat (file-name-sans-extension buffer-file-name) (read-from-minibuffer "View command: " default-cmd)
"." graphviz-dot-view-extension))) default-cmd)))
(format graphviz-dot-view-command (when graphviz-dot-save-before-view
(concat (file-name-sans-extension buffer-file-name) (save-buffer))
"." graphviz-dot-view-extension)))))
(if graphviz-dot-save-before-view
(save-buffer))
(setq novaproc (start-process-shell-command (setq novaproc (start-process-shell-command
(downcase mode-name) nil cmd)) (downcase mode-name) nil cmd))
(message (format "Executing `%s'..." cmd)))))) (message (format "Executing `%s'..." cmd))))))

View File

@ -31,8 +31,7 @@ Do not set `gdb-show-main' to true as we handle it manually here."
(split-window-horizontally) (split-window-horizontally)
(other-window 1) (other-window 1)
(gdb-set-window-buffer (gdb-set-window-buffer (gdb-get-buffer-create 'gdb-inferior-io))
(gdb-get-buffer-create 'gdb-inferior-io)))
(other-window 1) (other-window 1)
(gdb-set-window-buffer gud-comint-buffer) (gdb-set-window-buffer gud-comint-buffer)

View File

@ -3,7 +3,7 @@
(defun python-set-compiler () (defun python-set-compiler ()
"Returns the value of the shebang if any, `python-shell-interpreter' otherwise." "Returns the value of the shebang if any, `python-shell-interpreter' otherwise."
(let* ((firstline (let* ((firstline
(save-excursion (beginning-of-buffer) (buffer-substring-no-properties (line-beginning-position) (line-end-position)))) (save-excursion (goto-char (point-min)) (buffer-substring-no-properties (line-beginning-position) (line-end-position))))
(interpreter (interpreter
(if (not (string-match "^#!" firstline)) (if (not (string-match "^#!" firstline))
python-shell-interpreter python-shell-interpreter

View File

@ -28,16 +28,19 @@
(defcustom tex-compilation-delay 2 (defcustom tex-compilation-delay 2
"Seconds before hiding the compilation window." "Seconds before hiding the compilation window."
:type 'number) :type 'number
:group 'tex)
(defcustom tex-extension-list nil (defcustom tex-extension-list nil
"List of known TeX exentsions. This list is used by `tex-clean' "List of known TeX exentsions. This list is used by `tex-clean'
to purge all matching files." to purge all matching files."
:type '(repeat list)) :type '(repeat list)
:group 'tex)
(defcustom tex-index-command "makeindex" (defcustom tex-index-command "makeindex"
"The TeX index file generator." "The TeX index file generator."
:type 'string) :type 'string
:group 'tex)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Functions ;; Functions

View File

@ -10,10 +10,7 @@
"Update texinfo node menu automatically." "Update texinfo node menu automatically."
(interactive) (interactive)
(hack-local-variables) (hack-local-variables)
(let (texinfo-multiple-files-update (or tex-master-file buffer-file-name) t 8))
;; Master file.
((local-master (if (not masterfile) buffer-file-name masterfile)))
(texinfo-multiple-files-update local-master t 8)))
(add-hook-and-eval (add-hook-and-eval
'texinfo-mode-hook 'texinfo-mode-hook

View File

@ -86,10 +86,11 @@ the end after an ' = ' separtor."
(save-excursion (save-excursion
;; forward-line will remain on the same line if EOF has been reached. Need ;; forward-line will remain on the same line if EOF has been reached. Need
;; to check for it. ;; to check for it.
(let ((lang-in (or in itranslate-lang-input)) (let (line
(lang-in (or in itranslate-lang-input))
(lang-out (or out itranslate-lang-output))) (lang-out (or out itranslate-lang-output)))
(while (<= beg end) (while (<= beg end)
(goto-line beg) (forward-line beg)
(setq line (buffer-substring-no-properties (setq line (buffer-substring-no-properties
(line-beginning-position) (line-end-position))) (line-beginning-position) (line-end-position)))
(unless (string-match "^ *$" line) (unless (string-match "^ *$" line)

View File

@ -1,5 +1,6 @@
;;; Hack around SMIE ;;; Hack around SMIE
(require 'smie) (require 'smie)
(defcustom smie-align nil "Whether to align function arguments.") (defcustom smie-align nil "Whether to align function arguments.")
(defun smie-indent-exps () (defun smie-indent-exps ()

View File

@ -22,7 +22,7 @@
(set-face-background 'mode-line "white")) (set-face-background 'mode-line "white"))
;; (set-face-foreground 'link "#00ffff") ;; (set-face-foreground 'link "#00ffff")
(set-face-underline-p 'link t) (set-face-underline 'link t)
(set-face-foreground 'minibuffer-prompt "#00ffff") (set-face-foreground 'minibuffer-prompt "#00ffff")
(set-face-background 'region "#191970") (set-face-background 'region "#191970")
(set-face-attribute 'isearch nil :foreground "#8b0000" :background "white") (set-face-attribute 'isearch nil :foreground "#8b0000" :background "white")
@ -67,7 +67,7 @@
'sh-mode-hook 'sh-mode-hook
(lambda () (lambda ()
(set-face-foreground 'sh-heredoc "#00bfff") (set-face-foreground 'sh-heredoc "#00bfff")
(set-face-bold-p 'sh-heredoc nil))) (set-face-bold 'sh-heredoc nil)))
;; Eshell ;; Eshell
(add-hook (add-hook