diff options
| author | Mitch Taylor <mitch@mitchtaylor.xyz> | 2026-03-23 13:53:06 -0300 |
|---|---|---|
| committer | Mitch Taylor <mitch@mitchtaylor.xyz> | 2026-03-23 13:53:06 -0300 |
| commit | 41ba51ef22074fadc6e1aa14c217d99456e6ee8e (patch) | |
| tree | d053d89c6f2f5a0263b7c962c47395ba42b8aeb1 /files | |
| parent | ca302c7e4673f668e82547d2d1ef9afed5ec8c79 (diff) | |
sway autostart + emacs
Diffstat (limited to 'files')
| -rw-r--r-- | files/emacs/.emacs.d/post-init.el | 81 |
1 files changed, 81 insertions, 0 deletions
diff --git a/files/emacs/.emacs.d/post-init.el b/files/emacs/.emacs.d/post-init.el index ebd061c..edb6dad 100644 --- a/files/emacs/.emacs.d/post-init.el +++ b/files/emacs/.emacs.d/post-init.el @@ -7,6 +7,87 @@ (require 'auth-source-pass) (auth-source-pass-enable) +(use-package abbrev + :ensure nil + :custom + (save-abbrevs nil) + :config + (defun emacs-solo/abbrev--replace-placeholders () + "Replace placeholders ###1###, ###2###, ... with minibuffer input. +If ###@### is found, remove it and place point there at the end." + (let ((cursor-pos nil)) + (save-excursion + (goto-char (point-min)) + (let ((loop 0) + (values (make-hash-table :test 'equal))) + (while (re-search-forward "###\\([0-9]+\\|@\\)###" nil t) + (setq loop (1+ loop)) + (let* ((index (match-string 1)) + (start (match-beginning 0)) + (end (match-end 0))) + (cond + ((string= index "@") + (setq cursor-pos start) + (delete-region start end)) + (t + (let* ((key (format "###%s###" index)) + (val (or (gethash key values) + (let ((input (read-string (format "Value for %s: " key)))) + (puthash key input values) + input)))) + (goto-char start) + (delete-region start end) + (insert val) + (goto-char (+ start (length val)))))))))) + (when cursor-pos + (goto-char cursor-pos)))) + + (define-abbrev-table 'global-abbrev-table + '(;; Arrows + ("ra" "→") + ("la" "←") + ("ua" "↑") + ("da" "↓") + + ;; HTML entities + ("nb" " ") + ("lt" "<") + ("gt" ">") + + ;; Markdown + ("cb" "```@\n\n```" + (lambda () (search-backward "@") (delete-char 1))) + + ;; ORG + ("ocb" "#+BEGIN_SRC @\n\n#+END_SRC" + (lambda () (search-backward "@") (delete-char 1))) + ("oheader" "#+TITLE: ###1###\n#+AUTHOR: ###2###\n#+EMAIL: ###3###\n#+OPTIONS: toc:nil\n" + emacs-solo/abbrev--replace-placeholders) + + ;; JS/TS snippets + ("imp" "import { ###1### } from '###2###';" + emacs-solo/abbrev--replace-placeholders) + ("fn" "function ###1### () {\n ###@### ;\n};" + emacs-solo/abbrev--replace-placeholders) + ("clog" "console.log(\">>> LOG:\", { ###@### })" + emacs-solo/abbrev--replace-placeholders) + ("cwarn" "console.warn(\">>> WARN:\", { ###@### })" + emacs-solo/abbrev--replace-placeholders) + ("cerr" "console.error(\">>> ERR:\", { ###@### })" + emacs-solo/abbrev--replace-placeholders) + ("afn" "async function() {\n \n}" + (lambda () (search-backward "}") (forward-line -1) (end-of-line))) + ("ife" "(function() {\n \n})();" + (lambda () (search-backward ")();") (forward-line -1) (end-of-line))) + ("esdeps" "// eslint-disable-next-line react-hooks/exhaustive-deps" + (lambda () (search-backward ")();") (forward-line -1) (end-of-line))) + ("eshooks" "// eslint-disable-next-line react-hooks/rules-of-hooks" + (lambda () (search-backward ")();") (forward-line -1) (end-of-line))) + + ;; React/JSX + ("rfc" "const ###1### = () => {\n return (\n <div>###2###</div>\n );\n};" + emacs-solo/abbrev--replace-placeholders)))) + (setopt tab-always-indent 'complete read-buffer-completion-ignore-case t read-file-name-completion-ignore-case t |
