1 ;; get rid of custom from my init file
2 (setq custom-file "~/.emacs.d/emacs-custom.el")
5 (setq-default abbrev-mode t)
7 (expand-file-name "~/dotsnew/emacs/abbrev_defs"))
9 (defconst op/backup-dir
10 (expand-file-name "backups" user-emacs-directory))
11 (unless (file-exists-p op/backup-dir)
12 (make-directory op/backup-dir))
13 (setq backup-directory-alist `(("." . ,op/backup-dir)))
15 (setq use-dialog-box nil
17 require-final-newline t
21 enable-recursive-minibuffers t
24 next-error-message-highlight t
25 read-minibuffer-restore-windows nil
26 isearch-allow-motion t
27 calc-make-windows-dedicated t
28 user-mail-address "op@omarpolo.com")
30 (setq completion-ignore-case t
31 read-file-name-completion-ignore-case t
32 read-buffer-completion-ignore-case t)
34 ;; "diff refinement", i.e. highlighting the changes in a more granular
35 ;; way, is quite awful to have it enabled by default. sometimes is
36 ;; useful, but for me it's more of a visual noise most of the times.
37 (setq diff-refine nil)
39 ;; disable also the syntax highlighting in the diff buffers
40 (setq diff-font-lock-syntax nil)
42 (define-key global-map (kbd "C-x C-b") #'ibuffer)
43 (define-key global-map (kbd "M-g i") #'imenu)
46 "Just like `imenu', but always flattened!"
50 (define-key minibuffer-mode-map (kbd "C-w") #'backward-kill-word)
52 (defun op/reverse-other-window ()
53 "Like `other-window', but reverse."
56 (define-key global-map (kbd "C-x O") #'op/reverse-other-window)
58 (define-key global-map (kbd "C-x v f") #'vc-pull)
60 (setq uniquify-buffer-name-style 'forward
61 uniquify-strip-common-suffix t)
63 (setq-default scroll-up-aggressively 0.0
64 scroll-down-aggressively 0.0
65 scroll-preserve-screen-position t
66 next-screen-context-lines 1)
68 (define-key global-map (kbd "M-z") #'zap-up-to-char)
71 (setq whitespace-style '(face trailing)
72 backward-delete-char-untabify-method 'hungry
73 tab-always-indent 'complete
75 sentence-end-double-space t)
76 (setq-default indent-tabs-mode t)
78 (defun op/enable-tabs ()
79 "Enable `indent-tabs-mode' in the current buffer."
81 (setq-local indent-tabs-mode t))
83 (defun op/disable-tabs ()
84 "Disable `indent-tabs-mode' in the current buffer."
86 (setq-local indent-tabs-mode nil))
88 (add-hook 'conf-mode-hook #'op/enable-tabs)
89 (add-hook 'text-mode-hook #'op/enable-tabs)
90 (add-hook 'prog-mode-hook #'op/enable-tabs)
91 (add-hook 'prog-mode-hook #'whitespace-mode)
92 (add-hook 'text-mode-hook #'whitespace-mode)
94 (dolist (hook '(emacs-lisp-mode-hook
96 clojurescript-mode-hook
99 (add-hook hook #'op/disable-tabs))
101 (with-eval-after-load 'log-edit
102 (add-hook 'log-edit-mode #'auto-fill-mode))
104 ;; free the c-z binding
105 (define-key global-map (kbd "C-z") nil)
106 (define-key global-map (kbd "C-z V") #'variable-pitch-mode)
107 (define-key global-map (kbd "C-z n") #'display-line-numbers-mode)
109 (define-key global-map (kbd "M-SPC") #'cycle-spacing)
110 (define-key global-map (kbd "M-u") #'upcase-dwim)
111 (define-key global-map (kbd "M-l") #'downcase-dwim)
112 (define-key global-map (kbd "M-c") #'capitalize-dwim)
114 (let ((font "-misc-fixed-medium-r-semicondensed--13-120-75-75-c-60-iso10646-1"))
115 (set-frame-font font nil t)
116 (add-to-list 'default-frame-alist `(font . ,font)))
118 ;; fix the emojis too
119 (set-fontset-font t 'emoji '("Noto Emoji" . "iso10646-1")
125 (setq history-delete-duplicates t
127 savehist-save-minibuffer-history t)
128 (electric-pair-mode +1)
130 (define-key global-map (kbd "M-/") #'hippie-expand)
131 (setq hippie-expand-try-functions-list
133 try-expand-dabbrev-all-buffers
134 try-expand-dabbrev-from-kill
135 try-complete-file-name-partially
136 try-complete-file-name
137 try-expand-all-abbrevs
140 try-complete-lisp-symbol-partially
141 try-complete-lisp-symbol))
143 (setq isearch-lazy-count t
144 search-whitespace-regexp ".*?"
145 isearch-allow-scroll 'unlimited)
147 (defun op/buffer-to-side-window (place)
148 "Place the current buffer in the side window at PLACE."
149 (interactive (list (intern
150 (completing-read "Which side: "
151 '(top left right bottom)))))
152 (let ((buf (current-buffer)))
153 (display-buffer-in-side-window
154 buf `((window-height . 0.15)
157 (window-parameters . ((no-delete-other-windows . t)))))
160 (defun op/visit-new-migration-file (name)
161 "Visit a new SQL migration file named after NAME."
162 (interactive "Mname: ")
163 (let* ((name (replace-regexp-in-string " " "-" (string-trim name)))
164 (f (format "%s-%s.sql"
165 (format-time-string "%Y%m%d%H%M")
169 (defun op/fill-or-unfill (fn &optional justify region)
170 "Meant to be an adviced :around `fill-paragraph'.
171 FN is the original `fill-column'. If `last-command' is
172 `fill-paragraph', unfill it, fill it otherwise. Inspired from a
173 post on endless parentheses. Optional argument JUSTIFY and
174 REGION are passed to `fill-paragraph'."
176 (if (eq last-command 'fill-paragraph)
177 (progn (setq this-command nil)
180 (funcall fn justify region)))
181 (advice-add 'fill-paragraph :around #'op/fill-or-unfill)
183 (defmacro op/deftranspose (name scope key doc)
184 "Macro to produce transposition functions.
185 NAME is the function's symbol. SCOPE is the text object to
186 operate on. Optional DOC is the function's docstring.
188 Transposition over an active region will swap the object at
189 mark (region beginning) with the one at point (region end).
191 It can optionally define a key for the defined function in the
192 `global-map' if KEY is passed.
194 Originally from protesilaos' dotemacs."
195 (declare (indent defun))
200 (let ((x (intern (format "transpose-%s" ,scope))))
205 `(define-key global-map (kbd ,key) #',name))))
207 (op/deftranspose op/transpose-lines "lines" "C-x C-t"
208 "Transpose lines or swap over active region.")
210 (op/deftranspose op/transpose-paragraphs "paragraphs" "C-S-t"
211 "Transpose paragraph or swap over active region.")
213 (op/deftranspose op/transpose-sentences "sentences" "C-x M-t"
214 "Transpose sentences or swap over active region.")
216 (op/deftranspose op/transpose-sexps "sexps" "C-M-t"
217 "Transpose sexps or swap over active region.")
219 (op/deftranspose op/transpose-words "words" "M-t"
220 "Transpose words or swap over active region.")
222 (defun op/narrow-or-widen-dwim (p)
223 "Widen if the buffer is narrowed, narrow-dwim otherwise.
224 Dwim means: region, org-src-block, org-subtree or defun,
225 whichever applies first. Narrowing to org-src-blocks actually
226 calls `org-edit-src-code'.
228 With prefix P, don't widen, just narrow even if buffer is already
229 narrowed. With P being -, narrow to page instead of to defun.
231 Taken from endless parentheses."
233 (declare (interactive-only))
234 (cond ((and (buffer-narrowed-p) (not p)) (widen))
236 (narrow-to-region (region-beginning)
238 ((derived-mode-p 'org-mode)
239 ;; `org-edit-src-code' isn't a real narrowing
240 (cond ((ignore-errors (org-edit-src-code) t))
241 ((ignore-errors (org-narrow-to-block) t))
242 (t (org-narrow-to-subtree))))
243 ((eql p '-) (narrow-to-page))
244 (t (narrow-to-defun))))
246 (define-key global-map (kbd "C-c w") #'op/narrow-or-widen-dwim)
248 (with-eval-after-load 'dired
249 (add-hook 'dired-mode-hook #'dired-hide-details-mode)
250 (add-hook 'dired-mode-hook #'dired-omit-mode)
252 (define-key dired-mode-map (kbd "C-c w") #'wdired-change-to-wdired-mode)
255 (setq dired-listing-switches "-lahF"
257 dired-deletion-confirmer #'y-or-n-p
258 dired-do-revert-buffer t))
260 ;; just like telescope!
261 (with-eval-after-load 'diff-mode
262 (define-key diff-mode-map (kbd "M-SPC") #'scroll-down-command))
264 (with-eval-after-load 'elisp-mode
265 (add-hook 'emacs-lisp-mode-hook #'checkdoc-minor-mode)
266 (add-hook 'emacs-lisp-mode-hook #'prettify-symbols-mode)
267 (let ((map emacs-lisp-mode-map))
268 (define-key map (kbd "C-c C-k") #'eval-buffer)
269 (define-key map (kbd "C-c k") #'op/ert-all)
270 (define-key map (kbd "C-c C-z") #'op/ielm-repl)))
272 (with-eval-after-load 'help
273 (add-hook 'help-mode-hook #'visual-line-mode))
276 (add-to-list 'package-archives '("melpa" . "https://melpa.org/packages/") t)
278 ;; packages that i want to be installed
279 (dolist (pkg '(vc-got pdf-tools eglot nameless sly cider go-mode web-mode
280 lua-mode markdown-mode yaml-mode gemini-mode elfeed
281 form-feed shackle embark consult mct puni))
282 (unless (package-installed-p pkg)
283 (message "Installing %s" pkg)
284 (package-install pkg)))
286 (global-form-feed-mode +1)
288 (add-hook 'text-mode-hook #'puni-mode)
289 (add-hook 'prog-mode-hook #'puni-mode)
290 (define-key puni-mode-map (kbd "C-)") #'puni-slurp-forward)
291 (define-key puni-mode-map (kbd "C-(") #'puni-barf-forward)
293 (setq completion-styles '(basic substring initials flex partial-completion))
295 (require 'consult) ;; some stuff lacks an autoload and i don't want to debug it
297 (cl-loop for (key . func) in '(("C-x :" . consult-complex-command)
298 ("C-x b" . consult-buffer)
299 ("C-x 4 b" . consult-buffer-other-window)
300 ("C-x 5 b" . consult-buffer-other-frame)
301 ("C-x r b" . consult-bookmark)
302 ("C-x p b" . consult-project-buffer)
303 ("M-y" . consult-yank-pop)
304 ("M-g g" . consult-goto-line)
305 ("M-g M-g" . consult-goto-line)
306 ("M-g m" . consult-mark)
307 ("M-g i" . consult-imenu)
308 ("M-s l" . consult-line)
309 ("M-s L" . consult-line-multi)
310 ("M-s m" . consult-multi-occur))
311 do (define-key global-map (kbd key) func))
312 (add-hook 'completion-list-mode-hook #'consult-preview-at-point-mode)
314 (setq completions-detailed t)
315 (mct-minibuffer-mode +1)
318 ;; override the binding for the annoying mct-backward-updir.
319 (define-key mct-minibuffer-local-filename-completion-map
320 (kbd "DEL") #'backward-delete-char)
322 (setq mct-remove-shadowed-file-names t
323 mct-completions-format 'one-column
324 mct-completion-passlist '(Info-goto-node
331 consult-project-buffer
335 (with-eval-after-load 'cider
336 (define-key cider-repl-mode-map (kbd "C-c M-o") #'cider-repl-clear-buffer))
338 (with-eval-after-load 'go-mode
339 (add-hook 'go-mode-hook #'subword-mode))
341 (with-eval-after-load 'eglot
342 (define-key eglot-mode-map (kbd "<f1>") #'eglot-code-actions)
343 (define-key eglot-mode-map (kbd "<f2>") #'eglot-format)
344 (add-to-list 'eglot-ignored-server-capabilites
345 :documentHighlightProvider)
346 (add-to-list 'eglot-server-programs
347 '(c-mode . ("clangd" "--header-insertion=never"))))
349 (add-hook 'emacs-lisp-mode #'nameless-mode)
350 (with-eval-after-load 'nameless
351 (setq nameless-private-prefix t
352 nameless-affect-indentation-and-filling nil)
353 (define-key emacs-lisp-mode-map (kbd "_") #'nameless-insert-name-or-self-insert))
355 (add-to-list 'auto-mode-alist '("\\.html\\'" . web-mode))
356 (with-eval-after-load 'web-mode
357 (setq web-mode-markup-indent-offset 2
358 web-mode-css-indent-offset 2
359 web-mode-style-padding 0
360 web-mode-enable-engine-detection t)
361 (add-hook 'web-mode-hook #'op/disable-tabs)
363 ;; fix .dir-locals.el
364 (defun op/web-mode-fix-dir-locals ()
365 (when (derived-mode-p major-mode 'web-mode)
366 (web-mode-guess-engine-and-content-type)))
367 (add-hook 'hack-local-variables-hook #'op/web-mode-fix-dir-locals))
369 (with-eval-after-load 'css-mode
370 (add-hook 'css-mode-hook #'op/disable-tabs))
372 (with-eval-after-load 'flymake
373 (define-key prog-mode-map (kbd "C-c ! n") #'flymake-goto-next-error)
374 (define-key prog-mode-map (kbd "C-c ! p") #'flymake-goto-prev-error))
376 (with-eval-after-load 'cc-mode
377 (setq c-basic-offset 8
378 c-default-style "K&R")
379 (dolist (hook '(c-mode-hook c++-mode-hook))
380 (add-hook hook #'abbrev-mode)
381 (add-hook hook #'subword-mode))
382 (defun op/c-indent ()
384 (c-set-offset 'arglist-intro '+)
385 (c-set-offset 'arglist-cont-nonempty '*))
386 (add-hook 'c-mode-hook #'op/c-indent)
388 (defun op/c-add-include (path &optional localp)
389 "Include PATH at the start of the file.
390 If LOCALP is non-nil, the include will be \"local\"."
391 (interactive "Mheader to include: \nP")
394 "^#[ \t]*include[ \t]*\""
395 "^#[ \t]*include[ \t]*<"))
396 (ignore-re "^#include \"compat.h\"")
398 (goto-char (point-min))
399 (while (not (or (and (looking-at re)
400 (not (looking-at ignore-re)))
404 (error "Don't know where to insert the header"))
406 (insert "#include " (if localp "\"\"" "<>"))
409 (move-beginning-of-line 1)
412 (while (and (looking-at re)
415 (sort-lines nil start (point)))))
416 (define-key c-mode-map (kbd "C-c C-a") #'op/c-add-include))
418 (with-eval-after-load 'perl-mode
419 (setq perl-indent-level 8))
421 (with-eval-after-load 'sh-script
422 (setq sh-basic-offset 8
423 sh-indent-after-loop-construct 8
424 sh-indent-after-continuation nil))
428 (setq eshell-hist-ignoredups t)
430 (defun op/eshell-bufname (dir)
431 (concat "*eshell " (expand-file-name dir) "*"))
433 (defun op/eshell (arg)
434 "Run or jump to eshell in current project.
435 If called with prefix argument ARG always create a new eshell
438 (let* ((proj (project-current))
439 (dir (if (and proj (not arg))
442 (default-directory dir)
443 (eshell-buffer-name (let ((name (op/eshell-bufname dir)))
445 (generate-new-buffer name)
448 (define-key global-map (kbd "C-c e") #'op/eshell)
450 (with-eval-after-load 'eshell
451 (setq eshell-save-history-on-exit t
452 eshell-history-size 1024
454 eshell-compl-dir-ignore
455 "\\`\\(\\.\\.?\\|CVS\\|\\.svn\\|\\.git\\|\\.got\\)/\\'")
457 (defun op/eshell-after-cd (&rest _)
458 (rename-buffer (op/eshell-bufname default-directory) t))
460 (advice-add #'eshell/cd :after #'op/eshell-after-cd))
462 (with-eval-after-load 'esh-mode
463 (defun op/clear-eshell ()
465 (let ((inhibit-read-only t))
467 (eshell-send-input)))
469 (define-key eshell-command-map (kbd "M-o") #'op/clear-eshell))
473 (unless (package-installed-p 'sndio)
474 (package-install-file "~/w/sndio.el/sndio.el"))
478 (unless (package-installed-p 'saturn)
479 (package-install-file "~/w/saturn/GUI/saturn.el"))
483 (unless (package-installed-p 'simple-pass)
484 (package-install-file "~/.emacs.d/simple-pass.el"))
485 (define-key global-map (kbd "C-z p") #'simple-pass-copy)
491 (define-key global-map (kbd "C-x w") #'elfeed)
492 (with-eval-after-load 'elfeed
493 (define-key elfeed-show-mode-map (kbd "q") #'delete-window)
494 (define-key elfeed-show-mode-map (kbd "S-SPC") #'scroll-down-command)
495 (define-key elfeed-show-mode-map (kbd "M-SPC") #'scroll-down-command)
496 (setq elfeed-show-entry-switch #'pop-to-buffer
498 '("https://undeadly.org/cgi?action=rss&full=yes&items=10"
499 "http://www.tedunangst.com/flak/rss"
500 "https://www.dragonflydigest.com/feed"
501 "https://www.mirbsd.org/news.rss"
502 "https://www.mirbsd.org/announce.rss"
503 "https://bentsukun.ch/index.xml"
504 "https://drewdevault.com/feed.xml"
505 "https://www.cambus.net/atom.xml"
506 "https://dataswamp.org/~solene/rss.xml"
507 "https://briancallahan.net/blog/feed.xml"
508 "https://www.poolp.org/index.xml"
509 "https://jcs.org/rss"
510 "https://sanctum.geek.nz/arabesque/feed/"
511 "https://tech.toryanderson.com/"
512 "https://alexschroeder.ch/wiki?action=journal;search=-tag:rpg -tag:rsp;lang=en;title=English Diary without RPG Pages"
513 "http://boston.conman.org/bostondiaries.rss"
514 "https://emacsninja.com/feed.atom"
515 "https://bsdly.blogspot.com/feeds/posts/default"
516 "https://crawshaw.io/atom.xml"
517 "https://nullprogram.com/feed/"
518 "http://pragmaticemacs.com/feed/"
519 "https://emacsnotes.wordpress.com/feed/"
520 "https://metaredux.com/feed.xml"
521 "https://emacsredux.com/atom.xml"
522 "https://endlessparentheses.com/atom.xml"
523 "https://www.masteringemacs.org/feed"
524 "https://cestlaz.github.io/rss.xml"
525 "https://utcc.utoronto.ca/~cks/space/blog/?atom"
526 "https://irreal.org/blog/?feed=rss2"
527 "https://jao.io/blog/rss.xml"
528 "https://planet.lisp.org/rss20.xml"
529 "https://insideclojure.org/feed.xml"
530 "https://tech.toryanderson.com/index.xml"
531 "https://vermaden.wordpress.com/feed/"
532 "https://www.arp242.net/feed.xml"
533 "https://tymoon.eu/api/reader/atom"
534 "https://venam.nixers.net/blog/feed.xml"
535 "https://www.omarpolo.com/rss.xml"
536 "https://owarisubs.lacumpa.biz/feed/"
537 "https://asenshi.moe/feed/"
538 "https://godotengine.org/rss.xml"
540 "https://adventofcomputing.libsyn.com/rss"
542 "https://github.com/go-gitea/gitea/releases.atom"
544 "https://nitter.pussthecat.org/NanoRaptor/rss"
546 "https://github.com/yshui/picom/releases.atom"
547 "https://github.com/vslavik/poedit/releases.atom"
548 "https://github.com/TokTok/c-toxcore/releases.atom"
549 "https://github.com/alexander-akhmetov/python-telegram/releases.atom"
550 "https://github.com/paul-nameless/tg/releases.atom"
551 "https://github.com/YACReader/yacreader/releases.atom"
552 "https://github.com/luarocks/luarocks/releases.atom"
553 "https://github.com/okbob/pspg/releases.atom"
554 "https://github.com/taisei-project/taisei/releases.atom"
555 "https://github.com/recp/cglm/releases.atom"
556 "https://github.com/SCons/scons/releases.atom"
557 "https://git.sr.ht/~rjarry/aerc/refs/rss.xml"
559 "https://causal.agency/list/pounce.atom"
561 "https://www.crimsonmagic.me/feed/"
562 "https://fullybookedtls.wordpress.com/feed/"
564 "https://draculadaily.substack.com/feed")))
566 (setq shackle-default-rule nil
568 (let ((repls "\\*\\(cider-repl\\|sly-mrepl\\|ielm\\)")
569 (godot "\\*godot - .*\\*")
570 (vcs "\\*\\(Flymake\\|Package-Lint\\|vc-\\(git\\|got\\) :\\).*")
571 (elfeed "\\*elfeed-entry\\*")
572 (vmd "\\*vmd console .*"))
573 `(("*Async Shell Command*" :ignore t)
580 (occur-mode :select t
583 (diff-mode :select t)
601 ;; (setq display-buffer-alist nil)
603 (define-key global-map (kbd "M-g e") #'embark-act)
605 (with-eval-after-load 'embark
606 (defun op/target-filename+line ()
607 "Target a file with optional line number: file[:number]."
609 (let* ((beg (progn (skip-chars-backward "^[:space:]\n")
611 (end (progn (skip-chars-forward "^[:space:]\n")
613 (str (buffer-substring-no-properties beg end)))
615 (when (and (progn (goto-char beg)
616 (ffap-file-at-point))
617 (string-match ".+\\(:[[:digit:]]+\\)?:?" str))
618 `(file ,str ,beg . ,end))))))
620 (add-to-list 'embark-target-finders #'op/target-filename+line)
622 (defun op/acme-find-file (filename)
623 "Visit FILENAME like `find-file', but also jump to line if provided."
625 (if (not (string-match "\\(.+\\):\\([[:digit:]]+\\)" filename))
627 (let ((path (match-string 1 filename))
628 (line (string-to-number (match-string 2 filename))))
629 (with-current-buffer (find-file path)
630 (goto-line line))))))
632 (define-key embark-file-map (kbd "RET") #'op/acme-find-file))