summary refs log tree commit diff stats
path: root/definitions.el
diff options
context:
space:
mode:
Diffstat (limited to 'definitions.el')
-rw-r--r--definitions.el149
1 files changed, 0 insertions, 149 deletions
diff --git a/definitions.el b/definitions.el deleted file mode 100644 index 125c87e..0000000 --- a/definitions.el +++ /dev/null
@@ -1,149 +0,0 @@
1;;; definitions.el --- definitions for my Emacs config -*- lexical-binding: t; -*-
2
3(defun other-window-or-switch-buffer (&optional arg)
4 "Switch to the other window.
5If a window is the only buffer on a frame, switch buffer. When
6run with \\[universal-argument], unconditionally switch buffer."
7 (interactive "P")
8 (if (or arg (one-window-p))
9 (switch-to-buffer (other-buffer) nil t)
10 (other-window 1)))
11
12(defun cycle-spacing@ (&optional n)
13 ;; `cycle-spacing' is wildly different in 29.1 over 28.
14 "Negate N argument on `cycle-spacing'.
15That is, with a positive N, deletes newlines as well, leaving -N
16spaces. If N is negative, it will not delete newlines and leave
17N spaces."
18 (interactive "*p")
19 (cycle-spacing (- n)))
20
21(defun first-frame@set-fonts ()
22 (remove-hook 'server-after-make-frame-hook
23 #'first-frame@set-fonts)
24 (face-spec-set 'default
25 `((t :family "Recursive Mono Casual Static"
26 :height 110)))
27 ;; Emojis
28 (cl-loop with ffl = (font-family-list)
29 for font in '("Noto Emoji" "Noto Color Emoji"
30 "Segoe UI Emoji" "Apple Color Emoji"
31 "FreeSans" "FreeMono" "FreeSerif"
32 "Unifont" "Symbola")
33 if (member font ffl)
34 do (set-fontset-font t 'symbol font))
35 ;; International fonts
36 (cl-loop with ffl = (font-family-list)
37 for (charset . font)
38 in '((latin . "Noto Sans")
39 (han . "Noto Sans CJK SC Regular")
40 (kana . "Noto Sans CJK JP Regular")
41 (hangul . "Noto Sans CJK KR Regular")
42 (cjk-misc . "Noto Sans CJK KR Regular")
43 (khmer . "Noto Sans Khmer")
44 (lao . "Noto Sans Lao")
45 (burmese . "Noto Sans Myanmar")
46 (thai . "Noto Sans Thai")
47 (ethiopic . "Noto Sans Ethiopic")
48 (hebrew . "Noto Sans Hebrew")
49 (arabic . "Noto Sans Arabic")
50 (gujarati . "Noto Sans Gujarati")
51 (devanagari . "Noto Sans Devanagari")
52 (kannada . "Noto Sans Kannada")
53 (malayalam . "Noto Sans Malayalam")
54 (oriya . "Noto Sans Oriya")
55 (sinhala . "Noto Sans Sinhala")
56 (tamil . "Noto Sans Tamil")
57 (telugu . "Noto Sans Telugu")
58 (tibetan . "Noto Sans Tibetan"))
59 if (member font ffl)
60 do (set-fontset-font t charset font)))
61
62(defun switch-themes ()
63 (interactive)
64 (let ((current-theme (car custom-enabled-themes)))
65 (mapc #'disable-theme custom-enabled-themes)
66 (enable-theme (pcase current-theme
67 ('modus-operandi 'modus-vivendi)
68 ('modus-vivendi 'modus-operandi)))))
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(defvar no-tabs-modes '(emacs-lisp-mode
105 lisp-mode
106 scheme-mode
107 python-mode
108 haskell-mode)
109 "Modes /not/ to indent with tabs.")
110
111(defun indent-tabs-mode-maybe ()
112 (if (apply #'derived-mode-p no-tabs-modes)
113 (indent-tabs-mode -1)
114 (indent-tabs-mode 1)))
115
116(define-minor-mode truncate-lines-mode
117 "Buffer-local mode to toggle `truncate-lines'."
118 :lighter ""
119 (setq-local truncate-lines truncate-lines-mode))
120
121;;; Region or buffer stuff
122
123(defun call-with-region-or-buffer (fn &rest _r)
124 "Call function FN with current region or buffer.
125Good to use for :around advice."
126 (if (region-active-p)
127 (funcall fn (region-beginning) (region-end))
128 (funcall fn (point-min) (point-max))))
129
130(defun delete-trailing-whitespace-except-current-line ()
131 (save-excursion
132 (delete-trailing-whitespace (point-min)
133 (line-beginning-position))
134 (delete-trailing-whitespace (line-end-position)
135 (point-max))))
136
137(defun create-missing-directories ()
138 "Automatically create missing directories."
139 (let ((target-dir (file-name-directory buffer-file-name)))
140 (unless (file-exists-p target-dir)
141 (make-directory target-dir :parents))))
142
143
144(defun vc-remote-off ()
145 "Turn VC off when remote."
146 (when (file-remote-p (buffer-file-name))
147 (setq-local vc-handled-backends nil)))
148
149