[Misc] Move ‘defun’s in init.el to top-level

This commit is contained in:
Daniel - 2018-01-27 17:30:43 +01:00
parent 0db33fb843
commit 51a96a0ef2
Signed by: dbo
GPG Key ID: 4F63DB96D45AA9C6
1 changed files with 141 additions and 136 deletions

135
init.el
View File

@ -532,8 +532,11 @@ _h_ _l_ _o_k _y_ank
(use-package quail
:defer t
:config (progn
(defun db/add-symbols-to-TeX-input-method ()
:config (add-hook 'input-method-activate-hook
#'db/add-symbols-to-TeX-input-method))
(defun db/add-symbols-to-TeX-input-method ()
"Add some new symbols to TeX input method."
(when (string= current-input-method "TeX")
(let ((quail-current-package (assoc "TeX" quail-package-alist)))
(quail-define-rules
@ -563,8 +566,6 @@ _h_ _l_ _o_k _y_ank
("\\mathcalQ" ?𝒬)
("\\mathcalS" ?𝒮)
("\\mathfrakP" ?𝔓)))))
(add-hook 'input-method-activate-hook
#'db/add-symbols-to-TeX-input-method)))
(use-package server
:commands (server-running-p server-start))
@ -687,38 +688,38 @@ _h_ _l_ _o_k _y_ank
(setq network-security-level 'high
nsm-save-host-names t)
(defun db/sort-nsm-permanent-settings ()
(advice-add 'nsm-write-settings
:before #'db/sort-nsm-permanent-settings)))
(defun db/sort-nsm-permanent-settings ()
"Sort values in `nsm-permanent-host-settings."
(setq nsm-permanent-host-settings
(cl-sort nsm-permanent-host-settings
#'string<
:key #'second)))
(advice-add 'nsm-write-settings
:before #'db/sort-nsm-permanent-settings)))
(use-package gnutls
:defer t
:config (progn
(setq gnutls-log-level 0 ; too noisy otherwise
gnutls-min-prime-bits 1024
gnutls-verify-error t)
gnutls-verify-error t)))
(defun db/update-cert-file-directory (symbol new-value)
"Set SYMBOL to NEW-VALUE and, assuming that NEW-VALUE points
to a directory, add all certificate files in it to
`gnutls-trustfiles.
(defun db/update-cert-file-directory (symbol new-value)
"Set SYMBOL to NEW-VALUE and add all certificate in it to `gnutls-trustfiles.
Certificates are assumed to be of the form *.crt."
Assumes that NEW-VALUE points to a directory, and certificates
are assumed to be of the form *.crt."
(set symbol new-value)
(when (file-directory-p new-value)
(dolist (cert-file (directory-files new-value t ".crt$"))
(add-to-list 'gnutls-trustfiles cert-file))))
(defcustom db/cert-file-directory "~/.local/etc/certs/"
(defcustom db/cert-file-directory "~/.local/etc/certs/"
"Local directory with additional certificates."
:group 'personal-settings
:type 'string
:set #'db/update-cert-file-directory)))
:set #'db/update-cert-file-directory)
(use-package epg
:defer t
@ -791,8 +792,30 @@ Certificates are assumed to be of the form *.crt."
(add-to-list 'font-lock-maximum-decoration '(wdired-mode . 1))
(add-to-list 'font-lock-maximum-decoration '(dired-mode . 1))
;; https://oremacs.com/2017/03/18/dired-ediff/
(defun ora-ediff-files ()
(when on-windows
(setq dired-free-space-program nil))
(require 'dired-quick-sort)
(when on-windows
(setq ls-lisp-use-insert-directory-program t))
(dired-quick-sort-setup)
(bind-key [remap beginning-of-buffer]
#'dired-back-to-top dired-mode-map)
(bind-key [remap end-of-buffer]
#'dired-jump-to-bottom dired-mode-map)
(bind-key "z" 'dired-get-size dired-mode-map)
(unbind-key "s" dired-mode-map)
(unbind-key "<f1>" dired-mode-map)
(bind-key "e" #'ora-ediff-files dired-mode-map)))
(use-package find-dired
:commands (find-dired)
:config (setq find-ls-option '("-print0 | xargs -0 ls -ld" . "-ld")))
;; https://oremacs.com/2017/03/18/dired-ediff/
(defun ora-ediff-files ()
"Compare marked files in dired with ediff."
(interactive)
(lexical-let ((files (dired-get-marked-files))
(wnd (current-window-configuration)))
@ -812,28 +835,20 @@ Certificates are assumed to be of the form *.crt."
(set-window-configuration wnd))))
(error "No more than 2 files should be marked"))))
(when on-windows
(setq dired-free-space-program nil))
(require 'dired-quick-sort)
(when on-windows
(setq ls-lisp-use-insert-directory-program t))
(dired-quick-sort-setup)
(defun dired-back-to-top ()
(defun dired-back-to-top ()
"Jump to first non-trivial line in dired."
(interactive)
(goto-char (point-min))
(dired-next-line 2))
(defun dired-jump-to-bottom ()
(defun dired-jump-to-bottom ()
"Jump to last non-trivial line in dired."
(interactive)
(goto-char (point-max))
(dired-next-line -1))
(defun dired-get-size () ; from emacswiki, via oremacs
"print size of all files marked in the current dired buffer."
(defun dired-get-size () ; from emacswiki, via oremacs
"Print size of all files marked in the current dired buffer."
(interactive)
(let ((files (dired-get-marked-files)))
(with-temp-buffer
@ -844,19 +859,6 @@ Certificates are assumed to be of the form *.crt."
(re-search-backward "\\(^[0-9.,]+[a-za-z]+\\).*total$")
(match-string 1))))))
(bind-key [remap beginning-of-buffer]
#'dired-back-to-top dired-mode-map)
(bind-key [remap end-of-buffer]
#'dired-jump-to-bottom dired-mode-map)
(bind-key "z" 'dired-get-size dired-mode-map)
(unbind-key "s" dired-mode-map)
(unbind-key "<f1>" dired-mode-map)
(bind-key "e" #'ora-ediff-files dired-mode-map)))
(use-package find-dired
:commands (find-dired)
:config (setq find-ls-option '("-print0 | xargs -0 ls -ld" . "-ld")))
;; * Completion
@ -1040,15 +1042,15 @@ Certificates are assumed to be of the form *.crt."
(unbind-key "C-x C-j" term-raw-map)
(unbind-key "C-x g" term-raw-map))))
(use-package ansi-color
:commands (ansi-color-for-comint-mode-on)
:config (progn
;; http://endlessparentheses.com/ansi-colors-in-the-compilation-buffer-output.html
(defun endless/colorize-compilation ()
;; http://endlessparentheses.com/ansi-colors-in-the-compilation-buffer-output.html
(defun endless/colorize-compilation ()
"Colorize from `compilation-filter-start' to `point'."
(let ((inhibit-read-only t))
(ansi-color-apply-on-region compilation-filter-start (point))))
(use-package ansi-color
:commands (ansi-color-for-comint-mode-on)
:config (progn
(add-hook 'compilation-filter-hook #'endless/colorize-compilation)))
(use-package shell
@ -1082,17 +1084,18 @@ Certificates are assumed to be of the form *.crt."
(use-package elisp-mode
:defer t
:config (progn (add-hook 'emacs-lisp-mode-hook #'lispy-mode)
:config (progn
(add-hook 'emacs-lisp-mode-hook #'lispy-mode)
(add-hook 'emacs-lisp-mode-hook #'db/add-use-package-to-imenu)
(add-hook 'ielm-mode-hook #'eldoc-mode)
(add-hook 'emacs-lisp-mode-hook #'eldoc-mode)))
(defun db/add-use-package-to-imenu ()
(defun db/add-use-package-to-imenu ()
"Add `use-package statements to `imenu-generic-expression."
(add-to-list 'imenu-generic-expression
'("Used Packages"
"\\(^\\s-*(use-package +\\)\\(\\_<.+\\_>\\)"
2)))
(add-hook 'emacs-lisp-mode-hook #'db/add-use-package-to-imenu)
(add-hook 'ielm-mode-hook #'eldoc-mode)
(add-hook 'emacs-lisp-mode-hook #'eldoc-mode)))
(use-package geiser
:commands (geiser-mode))
@ -1169,17 +1172,21 @@ Certificates are assumed to be of the form *.crt."
(cmucl ("cmucl") :coding-system utf-8-unix)
(ccl ("ccl") :coding-system utf-8-unix)))
(eval-when-compile
(require 'slime-repl))
(setq slime-repl-history-remove-duplicates t
slime-repl-history-trim-whitespaces t)))
(use-package hy-mode
:commands (hy-mode org-babel-execute:hy)
:commands (hy-mode)
:config (progn
(add-hook 'hy-mode-hook #'lispy-mode)
(add-hook 'hy-mode-hook #'inferior-lisp)
(add-hook 'hy-mode-hook #'inferior-lisp)))
(defun org-babel-execute:hy (body params)
(defun org-babel-execute:hy (body params)
;; http://kitchingroup.cheme.cmu.edu/blog/2016/03/30/OMG-A-Lisp-that-runs-python/
"Execute hy code BODY with parameters PARAMS."
(ignore params)
(let* ((temporary-file-directory ".")
(tempfile (make-temp-file "hy-")))
@ -1188,8 +1195,7 @@ Certificates are assumed to be of the form *.crt."
(unwind-protect
(shell-command-to-string
(format "hy %s" tempfile))
(delete-file tempfile))))))
(delete-file tempfile))))
;; * TeX
@ -1253,18 +1259,17 @@ Certificates are assumed to be of the form *.crt."
:commands (electric-quote-mode))
(use-package elec-pair
:commands (electric-pair-mode
db/turn-off-local-electric-pair-mode)
:commands (electric-pair-mode)
:config (progn
(add-to-list 'electric-pair-pairs '(?“ . ?”))
(add-to-list 'electric-pair-text-pairs '(?“ . ?”))
(add-to-list 'electric-pair-pairs '(?„ . ?“))
(add-to-list 'electric-pair-text-pairs '(?„ . ?“))
(add-to-list 'electric-pair-text-pairs '(?„ . ?“))))
(defun db/turn-off-local-electric-pair-mode ()
"Turn off `electric-pair-mode locally."
(defun db/turn-off-local-electric-pair-mode ()
"Locally turn off electric pair mode."
(interactive)
(electric-pair-local-mode -1))))
(electric-pair-local-mode -1))
(use-package expand-region
:commands (er/expand-region))