about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--emacs.el152
1 files changed, 68 insertions, 84 deletions
diff --git a/emacs.el b/emacs.el index 6a2e13b..f6cec48 100644 --- a/emacs.el +++ b/emacs.el
@@ -2,7 +2,7 @@
2;; by Case Duckworth <acdw@acdw.net> 2;; by Case Duckworth <acdw@acdw.net>
3;; Bankruptcy 10: "Annoyance" 3;; Bankruptcy 10: "Annoyance"
4;; 4;;
5;; License: GPLv3+ 5;; License: GPLv3
6 6
7;;; Commentary: 7;;; Commentary:
8 8
@@ -67,40 +67,6 @@ basically."
67 (mapcar (lambda (ev) (cons t ev)) 67 (mapcar (lambda (ev) (cons t ev))
68 (listify-key-sequence kv))))) 68 (listify-key-sequence kv)))))
69 69
70(defun renz/sort-by-alpha-length (elems)
71 "Sort ELEMS first alphabetically, then by length."
72 (sort elems (lambda (c1 c2)
73 (or (string-version-lessp c1 c2)
74 (< (length c1) (length c2))))))
75
76(defun renz/sort-by-history (elems)
77 "Sort ELEMS by minibuffer history.
78Use `mct-sort-sort-by-alpha-length' if no history is available."
79 (if-let ((hist (and (not (eq minibuffer-history-variable t))
80 (symbol-value minibuffer-history-variable))))
81 (minibuffer--sort-by-position hist elems)
82 (renz/sort-by-alpha-length elems)))
83
84(defun renz/completion-category ()
85 "Return completion category."
86 (when-let ((window (active-minibuffer-window)))
87 (with-current-buffer (window-buffer window)
88 (completion-metadata-get
89 (completion-metadata (buffer-substring-no-properties
90 (minibuffer-prompt-end)
91 (max (minibuffer-prompt-end) (point)))
92 minibuffer-completion-table
93 minibuffer-completion-predicate)
94 'category))))
95
96(defun renz/sort-multi-category (elems)
97 "Sort ELEMS per completion category."
98 (pcase (renz/completion-category)
99 ('nil elems) ; no sorting
100 ('kill-ring elems)
101 ('project-file (renz/sort-by-alpha-length elems))
102 (_ (renz/sort-by-history elems))))
103
104(defun reset-faces () 70(defun reset-faces ()
105 (dolist (face '(font-lock-regexp-face 71 (dolist (face '(font-lock-regexp-face
106 font-lock-builtin-face 72 font-lock-builtin-face
@@ -115,7 +81,6 @@ Use `mct-sort-sort-by-alpha-length' if no history is available."
115 font-lock-number-face 81 font-lock-number-face
116 font-lock-keyword-face 82 font-lock-keyword-face
117 font-lock-set-face 83 font-lock-set-face
118 font-lock-warning-face
119 font-lock-punctuation-face 84 font-lock-punctuation-face
120 font-lock-constant-face 85 font-lock-constant-face
121 font-lock-type-face 86 font-lock-type-face
@@ -125,12 +90,14 @@ Use `mct-sort-sort-by-alpha-length' if no history is available."
125 font-lock-bracket-face)) 90 font-lock-bracket-face))
126 (face-spec-set face '((t :foreground unspecified 91 (face-spec-set face '((t :foreground unspecified
127 :background unspecified)))) 92 :background unspecified))))
128 (dolist (face '(font-lock-comment-face 93 (dolist (face '(font-lock-doc-face
129 font-lock-doc-face
130 font-lock-string-face)) 94 font-lock-string-face))
131 (face-spec-set face '((t :foreground unspecified 95 (face-spec-set face '((t :foreground unspecified
132 :background unspecified 96 :background unspecified
133 :slant italic))))) 97 :slant italic))))
98 (face-spec-set 'font-lock-comment-face
99 `((t :foreground ; :inherit doesn't work for some reason??
100 ,(face-foreground font-lock-doc-markup-face)))))
134 101
135(defun electric-pair-local-mode-disable () 102(defun electric-pair-local-mode-disable ()
136 "Disable `electric-pair-mode', locally." 103 "Disable `electric-pair-mode', locally."
@@ -204,8 +171,8 @@ buffer instead."
204 ;; `cycle-spacing' is wildly different in 29.1 over 28. 171 ;; `cycle-spacing' is wildly different in 29.1 over 28.
205 "Negate N argument on `cycle-spacing'. 172 "Negate N argument on `cycle-spacing'.
206That is, with a positive N, deletes newlines as well, leaving -N 173That is, with a positive N, deletes newlines as well, leaving -N
207spaces. If N is negative, it will not delete newlines and leave 174spaces. If N is negative, it will not delete newlines and leave N
208N spaces." 175spaces."
209 (interactive "*p") 176 (interactive "*p")
210 (cycle-spacing (- n))) 177 (cycle-spacing (- n)))
211 178
@@ -278,6 +245,10 @@ N spaces."
278(defun call-with-region-or-buffer (fn &rest _r) 245(defun call-with-region-or-buffer (fn &rest _r)
279 "Call function FN with current region or buffer. 246 "Call function FN with current region or buffer.
280Good to use for :around advice." 247Good to use for :around advice."
248 ;; This `interactive' form is needed to override the advised function's form,
249 ;; to avoid errors when the region isn't active. This means that FN must take
250 ;; 2 arguments, the beginning and the end of the region to act on.
251 (interactive)
281 (if (region-active-p) 252 (if (region-active-p)
282 (funcall fn (region-beginning) (region-end)) 253 (funcall fn (region-beginning) (region-end))
283 (funcall fn (point-min) (point-max)))) 254 (funcall fn (point-min) (point-max))))
@@ -430,7 +401,7 @@ If REQUIRE is a non-nil value, require the package after adding it."
430 :underline nil))) 401 :underline nil)))
431 402
432(setopt jabber-auto-reconnect t) 403(setopt jabber-auto-reconnect t)
433(setopt jabber-last-read-marker "~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~") 404(setopt jabber-last-read-marker " ")
434(setopt jabber-muc-decorate-presence-patterns 405(setopt jabber-muc-decorate-presence-patterns
435 '(("\\( enters the room ([^)]+)\\| has left the chatroom\\)$" . nil) 406 '(("\\( enters the room ([^)]+)\\| has left the chatroom\\)$" . nil)
436 ("Mode #.*" . jabber-muc-presence-dim) 407 ("Mode #.*" . jabber-muc-presence-dim)
@@ -454,7 +425,6 @@ disconnect first."
454 (interactive "P") 425 (interactive "P")
455 (when arg (jabber-disconnect)) 426 (when arg (jabber-disconnect))
456 (jabber-connect-all)) 427 (jabber-connect-all))
457(keymap-global-set "C-c j c" #'jabber-connect-all*)
458 428
459(keymap-global-set "C-c C-SPC" #'jabber-activity-switch-to) 429(keymap-global-set "C-c C-SPC" #'jabber-activity-switch-to)
460(with-eval-after-load 'jabber 430(with-eval-after-load 'jabber
@@ -464,6 +434,7 @@ disconnect first."
464 jabber-global-keymap) 434 jabber-global-keymap)
465 (keymap-global-set "C-x C-j" #'dired-jump)) 435 (keymap-global-set "C-x C-j" #'dired-jump))
466(keymap-global-set "C-x C-j" #'dired-jump) 436(keymap-global-set "C-x C-j" #'dired-jump)
437(keymap-set jabber-global-keymap "c" #'jabber-connect-all*)
467 438
468(with-eval-after-load 'dired 439(with-eval-after-load 'dired
469 (keymap-set dired-mode-map "C-j" #'dired-up-directory)) 440 (keymap-set dired-mode-map "C-j" #'dired-up-directory))
@@ -666,7 +637,7 @@ HOOK defaults to MODE-hook, and is used to trigger the hiding."
666(setopt use-file-dialog nil) 637(setopt use-file-dialog nil)
667(setopt use-short-answers t) 638(setopt use-short-answers t)
668(require 'savehist) 639(require 'savehist)
669(setopt history-length 1024) 640(setopt history-length t)
670(setopt history-delete-duplicates t) 641(setopt history-delete-duplicates t)
671(setopt savehist-save-minibuffer-history t) 642(setopt savehist-save-minibuffer-history t)
672(setopt savehist-autosave-interval 30) 643(setopt savehist-autosave-interval 30)
@@ -832,8 +803,6 @@ HOOK defaults to MODE-hook, and is used to trigger the hiding."
832 "Timer running `persist-settings-hook'.") 803 "Timer running `persist-settings-hook'.")
833 804
834(add-hook 'persist-settings-hook #'save-place-kill-emacs-hook) 805(add-hook 'persist-settings-hook #'save-place-kill-emacs-hook)
835(add-hook 'persist-settings-hook #'recentf-save-list)
836(add-hook 'persist-settings-hook #'savehist-autosave)
837(add-hook 'persist-settings-hook #'bookmark-exit-hook-internal) 806(add-hook 'persist-settings-hook #'bookmark-exit-hook-internal)
838(with-eval-after-load 'em-hist 807(with-eval-after-load 'em-hist
839 (add-hook 'persist-settings-hook #'eshell-save-some-history)) 808 (add-hook 'persist-settings-hook #'eshell-save-some-history))
@@ -867,6 +836,18 @@ HOOK defaults to MODE-hook, and is used to trigger the hiding."
867(setopt org-log-into-drawer t) 836(setopt org-log-into-drawer t)
868(setopt org-clock-into-drawer t) 837(setopt org-clock-into-drawer t)
869(setopt org-special-ctrl-a/e t) 838(setopt org-special-ctrl-a/e t)
839(setopt org-special-ctrl-k t)
840(setopt org-archive-mark-done t)
841(setopt org-agenda-window-setup 'current-window)
842(setopt org-agenda-restore-windows-after-quit t)
843(setopt org-agenda-skip-deadline-if-done t)
844(setopt org-agenda-skip-scheduled-if-done t)
845(setopt org-agenda-inhibit-startup t)
846(setopt org-deadline-warning-days 0)
847(setopt org-cycle-separator-lines 0)
848(setopt org-agenda-span 14)
849
850(add-hook 'org-agenda-after-show-hook #'org-narrow-to-subtree)
870 851
871(defmacro org-insert-or-surround (character) 852(defmacro org-insert-or-surround (character)
872 (let ((c (gensym))) 853 (let ((c (gensym)))
@@ -1201,45 +1182,19 @@ ORG-EXPORT-ARGS are passed to `org-export-to-buffer'."
1201(add-hook 'completion-list-mode-hook #'truncate-lines-mode) 1182(add-hook 'completion-list-mode-hook #'truncate-lines-mode)
1202(add-hook 'minibuffer-setup-hook #'truncate-lines-mode) 1183(add-hook 'minibuffer-setup-hook #'truncate-lines-mode)
1203 1184
1204(ensure-package 'prescient nil t) 1185(setopt completion-auto-help 'visible)
1205(setopt completion-styles '(prescient basic)) 1186(setopt completion-auto-select 'second-tab)
1206(setopt completion-category-overrides 1187(setopt completions-header-formato nil)
1207 '((file (styles basic partial-completion)))) 1188;; Up/down when completing in the minibuffer
1208(prescient-persist-mode) 1189(keymap-set minibuffer-local-map "C-p" #'minibuffer-previous-completion)
1209(add-hook 'persist-settings-hook #'prescient--save) 1190(keymap-set minibuffer-local-map "C-n" #'minibuffer-next-completion)
1191;; Up/down when competing in a normal buffer
1192(keymap-set completion-in-region-mode-map "C-p"
1193 #'minibuffer-previous-completion)
1194(keymap-set completion-in-region-mode-map "C-n" #'minibuffer-next-completion)
1195(keymap-set completion-in-region-mode-map "RET" #'minibuffer-choose-completion)
1210 1196
1211(define-minor-mode good-completions-mode 1197;;; Other stuff
1212 "A mode for completing good."
1213 :lighter ""
1214 :global t
1215 (setq completion-auto-help (when good-completions-mode 'always))
1216 (setq completion-auto-select (when good-completions-mode 'second-tab))
1217 (setq completions-format (if good-completions-mode 'one-column 'horizontal))
1218 (setq completions-header-format nil)
1219 (setq completions-max-height 16)
1220 (cond
1221 (good-completions-mode
1222 ;; Turn off other completion frameworks
1223 (icomplete-mode -1)
1224 (icomplete-vertical-mode -1)
1225 (fido-mode -1)
1226 (fido-vertical-mode -1)
1227 ;; Up/down when completing in the minibuffer
1228 (keymap-set minibuffer-local-map "C-p"
1229 #'minibuffer-previous-completion)
1230 (keymap-set minibuffer-local-map "C-n"
1231 #'minibuffer-next-completion)
1232 ;; Up/down when competing in a normal buffer
1233 (keymap-set completion-in-region-mode-map "C-p"
1234 #'minibuffer-previous-completion)
1235 (keymap-set completion-in-region-mode-map "C-n"
1236 #'minibuffer-next-completion)
1237 (keymap-set completion-in-region-mode-map "RET"
1238 #'minibuffer-choose-completion)
1239 (setq completion-in-region-function #'completion--in-region))
1240 (t)))
1241
1242(good-completions-mode)
1243 1198
1244(comment "Unnecessary after being defined." 1199(comment "Unnecessary after being defined."
1245 (ensure-package 'wiki-abbrev t t) 1200 (ensure-package 'wiki-abbrev t t)
@@ -1322,7 +1277,36 @@ ORG-EXPORT-ARGS are passed to `org-export-to-buffer'."
1322(ensure-package 'pulse-location t t) 1277(ensure-package 'pulse-location t t)
1323(pulse-location-mode) 1278(pulse-location-mode)
1324(hide-minor 'pulse-location-mode) 1279(hide-minor 'pulse-location-mode)
1280(setopt pulse-flag t)
1325 1281
1326(define-advice eval-region (:around (orig start end &rest args) pulse) 1282(define-advice eval-region (:around (orig start end &rest args) pulse)
1327 (apply orig start end args) 1283 (apply orig start end args)
1328 (pulse-momentary-highlight-region start end)) 1284 (pulse-momentary-highlight-region start end))
1285(put 'list-timers 'disabled nil)
1286
1287(defun string-intersperse (strings delim)
1288 "Intersperse STRINGS with DELIM and return the concatenated result."
1289 (cl-loop for string in strings
1290 concat (concat delim string) into acc
1291 finally return (substring acc (length delim))))
1292
1293(add-to-list 'inhibit-message-regexps
1294 (string-intersperse (map 'list #'expand-file-name
1295 (list recentf-save-file
1296 save-place-file))
1297 "\\|"))
1298
1299(add-to-list 'set-message-functions 'inhibit-message)
1300
1301(ensure-package 'web-mode)
1302(add-to-list 'auto-mode-alist '("\\.phtml\\'" . web-mode))
1303(add-to-list 'auto-mode-alist '("\\.tpl\\.php\\'" . web-mode))
1304(add-to-list 'auto-mode-alist '("\\.[agj]sp\\'" . web-mode))
1305(add-to-list 'auto-mode-alist '("\\.as[cp]x\\'" . web-mode))
1306(add-to-list 'auto-mode-alist '("\\.erb\\'" . web-mode))
1307(add-to-list 'auto-mode-alist '("\\.mustache\\'" . web-mode))
1308(add-to-list 'auto-mode-alist '("\\.djhtml\\'" . web-mode))
1309(add-to-list 'auto-mode-alist '("\\.html?\\'" . web-mode))
1310
1311(add-hook 'help-fns-describe-function-functions
1312 #'shortdoc-help-fns-examples-function)