changeset 31: |
f28229bc9b58 |
parent 30: |
bb274c6c126a |
child 32: |
62d07dc38929 |
author: |
ellis <ellis@rwest.io> |
date: |
Sat, 04 Nov 2023 19:31:51 -0400 |
files: |
emacs/default.el emacs/keys.el emacs/util.el |
description: |
emacs defaults |
1.1--- a/emacs/default.el Sat Nov 04 18:46:19 2023 -0400
1.2+++ b/emacs/default.el Sat Nov 04 19:31:51 2023 -0400
1.3@@ -7,41 +7,42 @@
1.4 (put 'list-threads 'disabled nil)
1.5 (put 'list-timers 'disabled nil)
1.6
1.7-(setq-default make-backup-files nil
1.8- auto-save-list-file-prefix (expand-file-name "auto-save/." user-emacs-directory)
1.9- tramp-auto-save-directory (expand-file-name "auto-save/tramp/" user-emacs-directory)
1.10- dired-free-space nil
1.11- confirm-kill-emacs nil
1.12- confirm-kill-processes nil
1.13- use-short-answers t
1.14- display-time-format "%Y-%m-%d %H:%M"
1.15- ring-bell-function 'ignore
1.16- gc-cons-percentage 0.6
1.17- completion-ignore-case t
1.18- ;; epa-pinentry-mode 'loopback
1.19- shr-use-colors nil
1.20- shr-use-fonts nil
1.21- shr-max-image-proportion 0.6
1.22- shr-image-animate nil
1.23- shr-discard-aria-hidden t
1.24- bookmark-default-file (expand-file-name "bookmarks" user-emacs-directory)
1.25- project-list-file (expand-file-name "projects" user-emacs-directory)
1.26- emms-directory (expand-file-name "emms" user-emacs-directory)
1.27- gnus-cache-directory (expand-file-name "gnus" user-emacs-directory)
1.28- url-cache-directory (expand-file-name "url" user-emacs-directory)
1.29- tab-always-indent 'complete
1.30- shr-cookie-policy nil
1.31- browse-url-browser-function 'browse-url-default-browser
1.32- eww-search-prefix "https://duckduckgo.com/html?q="
1.33- url-privacy-level '(email agent cookies lastloc)
1.34- view-read-only t
1.35- tramp-default-method "sshx")
1.36+(setq-default
1.37+ make-backup-files nil
1.38+ auto-save-list-file-prefix (expand-file-name "auto-save/." user-emacs-directory)
1.39+ tramp-auto-save-directory (expand-file-name "auto-save/tramp/" user-emacs-directory)
1.40+ dired-free-space nil
1.41+ confirm-kill-emacs nil
1.42+ confirm-kill-processes nil
1.43+ use-short-answers t
1.44+ display-time-format "%Y-%m-%d %H:%M"
1.45+ ring-bell-function 'ignore
1.46+ gc-cons-percentage 0.6
1.47+ completion-ignore-case t
1.48+ ;; epa-pinentry-mode 'loopback
1.49+ shr-use-colors nil
1.50+ shr-use-fonts nil
1.51+ shr-max-image-proportion 0.6
1.52+ shr-image-animate nil
1.53+ shr-discard-aria-hidden t
1.54+ bookmark-default-file (expand-file-name "bookmarks" user-emacs-directory)
1.55+ project-list-file (expand-file-name "projects" user-emacs-directory)
1.56+ emms-directory (expand-file-name "emms" user-emacs-directory)
1.57+ gnus-cache-directory (expand-file-name "gnus" user-emacs-directory)
1.58+ url-cache-directory (expand-file-name "url" user-emacs-directory)
1.59+ tab-always-indent 'complete
1.60+ shr-cookie-policy nil
1.61+ browse-url-browser-function 'browse-url-default-browser
1.62+ eww-search-prefix "https://duckduckgo.com/html?q="
1.63+ url-privacy-level '(email agent cookies lastloc)
1.64+ view-read-only t
1.65+ tramp-default-method "sshx")
1.66
1.67-(when (string= system-type "darwin")
1.68+(when-sys= "darwin"
1.69 (setq-default dired-use-ls-dired nil))
1.70
1.71 ;;; Variables
1.72-(defvar default-theme 'modus-vivendi)
1.73+(defvar default-theme 'modus-vivendi-deuteranopia)
1.74 (defvar company-domain "compiler.company")
1.75 (defvar company-name "The Compiler Company, LLC")
1.76 (defvar company-vc-domain "vc.compiler.company")
1.77@@ -161,6 +162,122 @@
1.78 ;;; Bash
1.79 (setq sh-basic-offset 2)
1.80
1.81+;;; Comments
1.82+(defcustom prog-comment-keywords
1.83+ '("TODO" "REVIEW" "FIX" "HACK" "RESEARCH")
1.84+ "List of strings with comment keywords."
1.85+ :group 'default)
1.86+
1.87+(defcustom prog-comment-timestamp-format-concise "%F"
1.88+ "Specifier for date in `prog-comment-timestamp-keyword'.
1.89+Refer to the doc string of `format-time-string' for the available
1.90+options."
1.91+ :group 'default)
1.92+
1.93+(defcustom prog-comment-timestamp-format-verbose "%F %T %z"
1.94+ "Like `prog-comment-timestamp-format-concise', but longer."
1.95+ :group 'default)
1.96+
1.97+;;;###autoload
1.98+(defun prog-comment-dwim (arg)
1.99+ "Flexible, do-what-I-mean commenting.
1.100+
1.101+If region is active and ARG is either a numeric argument greater
1.102+than one or a universal prefix (\\[universal-argument]), then
1.103+apply `comment-kill' on all comments in the region.
1.104+
1.105+If the region is active and no ARG is supplied, or is equal to a
1.106+numeric prefix of 1, then toggle the comment status of the region.
1.107+
1.108+Else toggle the comment status of the line at point. With a
1.109+numeric prefix ARG, do so for ARGth lines (negative prefix
1.110+operates on the lines before point)."
1.111+ (interactive "p")
1.112+ (cond
1.113+ ((and (> arg 1) (use-region-p))
1.114+ (let* ((beg (region-beginning))
1.115+ (end (region-end))
1.116+ (num (count-lines beg end)))
1.117+ (save-excursion
1.118+ (goto-char beg)
1.119+ (comment-kill num))))
1.120+ ((use-region-p)
1.121+ (comment-or-uncomment-region (region-beginning) (region-end)))
1.122+ (t
1.123+ (save-excursion (comment-line (or arg 1))))))
1.124+
1.125+(defvar prog-comment--keyword-hist '()
1.126+ "Input history of selected comment keywords.")
1.127+
1.128+(defun prog-comment--keyword-prompt (keywords)
1.129+ "Prompt for candidate among KEYWORDS."
1.130+ (let ((def (car prog-comment--keyword-hist)))
1.131+ (completing-read
1.132+ (format "Select keyword [%s]: " def)
1.133+ keywords nil nil nil 'prog-comment--keyword-hist def)))
1.134+
1.135+
1.136+;;;###autoload
1.137+(defun prog-comment-timestamp-keyword (keyword &optional verbose)
1.138+ "Add timestamped comment with KEYWORD.
1.139+
1.140+When called interactively, the list of possible keywords is that
1.141+of `prog-comment-keywords', though it is possible to
1.142+input arbitrary text.
1.143+
1.144+If point is at the beginning of the line or if line is empty (no
1.145+characters at all or just indentation), the comment is started
1.146+there in accordance with `comment-style'. Any existing text
1.147+after the point will be pushed to a new line and will not be
1.148+turned into a comment.
1.149+
1.150+If point is anywhere else on the line, the comment is indented
1.151+with `comment-indent'.
1.152+
1.153+The comment is always formatted as 'DELIMITER KEYWORD DATE:',
1.154+with the date format being controlled by the variable
1.155+`prog-comment-timestamp-format-concise'.
1.156+
1.157+With optional VERBOSE argument (such as a prefix argument
1.158+`\\[universal-argument]'), use an alternative date format, as
1.159+specified by `prog-comment-timestamp-format-verbose'."
1.160+ (interactive
1.161+ (list
1.162+ (prog-comment--keyword-prompt prog-comment-keywords)
1.163+ current-prefix-arg))
1.164+ (let* ((date (if verbose
1.165+ comment-timestamp-format-verbose
1.166+ prog-comment-timestamp-format-concise))
1.167+ (string (format "%s %s: " keyword (format-time-string date)))
1.168+ (beg (point)))
1.169+ (cond
1.170+ ((or (eq beg (point-at-bol))
1.171+ (default-line-regexp-p 'empty))
1.172+ (let* ((maybe-newline (unless (default-line-regexp-p 'empty 1) "\n")))
1.173+ ;; NOTE 2021-07-24: we use this `insert' instead of
1.174+ ;; `comment-region' because of a yet-to-be-determined bug that
1.175+ ;; traps `undo' to the two states between the insertion of the
1.176+ ;; string and its transformation into a comment.
1.177+ (insert
1.178+ (concat comment-start
1.179+ ;; NOTE 2021-07-24: See function `comment-add' for
1.180+ ;; why we need this.
1.181+ (make-string
1.182+ (comment-add nil)
1.183+ (string-to-char comment-start))
1.184+ comment-padding
1.185+ string
1.186+ comment-end))
1.187+ (indent-region beg (point))
1.188+ (when maybe-newline
1.189+ (save-excursion (insert maybe-newline)))))
1.190+ (t
1.191+ (comment-indent t)
1.192+ (insert (concat " " string))))))
1.193+
1.194+(setq hexl-bits 8)
1.195+(setq tab-width 4)
1.196+
1.197 ;;; Keyboard Macros
1.198 (defun toggle-macro-recording ()
1.199 (interactive)
2.1--- a/emacs/keys.el Sat Nov 04 18:46:19 2023 -0400
2.2+++ b/emacs/keys.el Sat Nov 04 19:31:51 2023 -0400
2.3@@ -23,7 +23,8 @@
2.4 "R" #'global-auto-revert-mode
2.5 "t" #'toggle-frame-tab-bar
2.6 "d" #'toggle-debug-on-error
2.7- "SPC" #'toggle-macro-recording)
2.8+ "SPC" #'toggle-macro-recording
2.9+ "w" #'toggle-theme)
2.10
2.11 (defvar-keymap status-map
2.12 :doc "User-specified keymap for status functions. Usually bound to 'C-c c .'."
2.13@@ -35,11 +36,23 @@
2.14 "d" #'list-dynamic-libraries
2.15 "P" #'list-packages)
2.16
2.17+(defvar-keymap server-map
2.18+ :doc "User-specified keymap for server functions. Usually bound to 'C-c c q'."
2.19+ "q" #'kill-emacs
2.20+ "r" #'kill-emacs-restart)
2.21+
2.22+(defvar-keymap review-map
2.23+ :doc "User-specified keymap for review functions. Usually bound to 'C-c c r'."
2.24+ "s" #'flyspell-buffer
2.25+ "SPC" #'whitespace-cleanup)
2.26+
2.27 (defvar-keymap user-map
2.28 :doc "User-specified keymap usually bound to 'C-c c' and populated in 'custom.el'."
2.29 :prefix 'user-map
2.30 "c" #'org-capture
2.31 "l" #'org-store-link
2.32+ "f" #'load-file
2.33+ "u" #'compile
2.34 "a" #'org-agenda
2.35 "<return>" #'shell
2.36 "C-<return>" #'term
2.37@@ -48,10 +61,19 @@
2.38 "s" #'speedbar
2.39 "SPC" toggle-map
2.40 "." status-map
2.41+ "r" review-map
2.42+ "q" server-map
2.43 "<tab>" #'outline-cycle
2.44 "<backtab>" #'outline-cycle-buffer
2.45 "z" #'scratch-new
2.46- "Z" #'default-scratch-buffer)
2.47+ "Z" #'default-scratch-buffer
2.48+ ";" #'prog-comment-dwim
2.49+ "C-;" #'prog-comment-timestamp-keyword)
2.50+
2.51+;;; Modes
2.52+(keymap-set conf-toml-mode-map "C-c C-c C-r" #'rust-run)
2.53+(keymap-set conf-toml-mode-map "C-c C-c C-u" #'rust-compile)
2.54+(keymap-set conf-toml-mode-map "C-c C-c C-t" #'rust-test)
2.55
2.56 ;;; C-x
2.57 ;; (keymap-set ctl-x-map "C-b" #'ibuffer)
3.1--- a/emacs/util.el Sat Nov 04 18:46:19 2023 -0400
3.2+++ b/emacs/util.el Sat Nov 04 19:31:51 2023 -0400
3.3@@ -3,6 +3,7 @@
3.4 ;;; Code:
3.5 (require 'cl-lib)
3.6
3.7+;;; Helpers
3.8 (defun group (source n)
3.9 "This is Paul Graham's group utility from 'On Lisp'.
3.10
3.11@@ -55,10 +56,7 @@
3.12 Concat ARGS and return a newly interned symbol."
3.13 (intern (apply #'mkstr args)))
3.14
3.15-(defmacro when-sys= (name body)
3.16- "(when (string= (system-name) NAME) BODY)"
3.17- `(when ,(string= (system-name) name) ,body))
3.18-
3.19+;;; Packages
3.20 (defun add-to-load-path (&rest paths)
3.21 "Add PATHS to `load-path'."
3.22 (mapc (lambda (x)
3.23@@ -67,6 +65,15 @@
3.24 ('_ (cl-pushnew x load-path))))
3.25 paths))
3.26
3.27+(defmacro add-packages (&rest pkgs)
3.28+ "add list of packages PKGS to `package-selected-packages'"
3.29+ `(mapc (lambda (x) (add-to-list 'package-selected-packages x)) ',pkgs))
3.30+
3.31+;;; OS
3.32+(defmacro when-sys= (name body)
3.33+ "(when (string= (system-name) NAME) BODY)"
3.34+ `(when ,(string= (system-name) name) ,body))
3.35+
3.36 (defun join-paths (root &rest dirs)
3.37 "helper function for joining strings to a path."
3.38 (let ((result root))
3.39@@ -74,9 +81,107 @@
3.40 (setq result (concat (file-name-as-directory result) dir)))
3.41 result))
3.42
3.43-(defmacro add-packages (&rest pkgs)
3.44- "add list of packages PKGS to `package-selected-packages'"
3.45- `(mapc (lambda (x) (add-to-list 'package-selected-packages x)) ',pkgs))
3.46+(defun wc (&optional start end)
3.47+ "Return a 3-element list with lines, words and characters in
3.48+region or whole buffer."
3.49+ (interactive)
3.50+ (let ((n 0)
3.51+ (start (if mark-active (region-beginning) (point-min)))
3.52+ (end (if mark-active (region-end) (point-max))))
3.53+ (save-excursion
3.54+ (goto-char start)
3.55+ (while (< (point) end) (if (forward-word 1) (setq n (1+ n)))))
3.56+ (list (count-lines start end) n (- end start))))
3.57+
3.58+;;; Regexps
3.59+(defvar default-line-regexp-alist
3.60+ '((empty . "[\s\t]*$")
3.61+ (indent . "^[\s\t]+")
3.62+ (non-empty . "^.+$")
3.63+ (list . "^\\([\s\t#*+]+\\|[0-9]+[^\s]?[).]+\\)")
3.64+ (heading . "^[=-]+"))
3.65+ "Alist of regexp types used by `default-line-regexp-p'.")
3.66+
3.67+(defun default-line-regexp-p (type &optional n)
3.68+ "Test for TYPE on line.
3.69+TYPE is the car of a cons cell in
3.70+`default-line-regexp-alist'. It matches a regular
3.71+expression.
3.72+With optional N, search in the Nth line from point."
3.73+ (save-excursion
3.74+ (goto-char (point-at-bol))
3.75+ (and (not (bobp))
3.76+ (or (beginning-of-line n) t)
3.77+ (save-match-data
3.78+ (looking-at
3.79+ (alist-get type default-line-regexp-alist))))))
3.80+
3.81+;;; Time
3.82+(defun format-iso-week-number (&optional date)
3.83+ "format DATE as ISO week number with week days starting on
3.84+ Monday. If DATE is nil use current date."
3.85+ (let* ((week (format-time-string "%W" date))
3.86+ (prefix (if (= (length week) 1)
3.87+ "w0" "w")))
3.88+ (concat prefix week)))
3.89+
3.90+(defun last-day-of-year (&optional date)
3.91+ "Return the last day of the year as time."
3.92+ (encode-time 0 0 0 31 12 (nth 5 (decode-time
3.93+ (or date (current-time))))))
3.94+
3.95+(defun last-day-of-month (&optional date)
3.96+ "Return the last day of month as time."
3.97+ (let* ((now (decode-time (or date (current-time))))
3.98+ (month (nth 4 now))
3.99+ (year (nth 5 now))
3.100+ (last-day-of-month (calendar-last-day-of-month month year)))
3.101+ (encode-time 0 0 0 last-day-of-month month year)))
3.102+
3.103+(defun last-day-of-week (&optional date)
3.104+ "Return the last day of the week as time."
3.105+ (let* ((now (or date (current-time)))
3.106+ (datetime (decode-time now))
3.107+ (dow (nth 6 datetime)))
3.108+ (time-add now (days-to-time (- 7 dow)))))
3.109+
3.110+(defun first-day-of-week (&optional date)
3.111+ "Return the first day of the week as time."
3.112+ (let* ((now (or date (current-time)))
3.113+ (datetime (decode-time now))
3.114+ (dow (nth 6 datetime)))
3.115+ (time-subtract now (days-to-time dow))))
3.116+
3.117+;;; VC
3.118+(defvar git-check-ignore t
3.119+ "When non-nil, check and obey '.gitignore' files.")
3.120+
3.121+(defun git-check-ignore (&optional dir)
3.122+ "Return a list of files to be ignored in DIR (defaults to
3.123+`default-directory'). Note that this does NOT include the .git
3.124+directory."
3.125+ (interactive)
3.126+ (with-dir (or dir default-directory)
3.127+ (mapcar (lambda (x)
3.128+ (replace-regexp-in-string "\\\"" ""
3.129+ (replace-regexp-in-string "\\\\\\(.\\|\n|\"\\)" "\\1" x)))
3.130+ (split-string
3.131+ (shell-command-to-string
3.132+ "pwsh.exe -c git check-ignore $(ls)")))))
3.133+
3.134+(defun git-dir-p (dir)
3.135+ "Return non-nil if DIR is a '.git' directory."
3.136+ (when (string=
3.137+ ".git"
3.138+ (file-name-nondirectory
3.139+ (directory-file-name dir)))
3.140+ t))
3.141+
3.142+;;; Server
3.143+;;;###autoload
3.144+(defun kill-emacs-restart (&optional arg)
3.145+ (interactive)
3.146+ (kill-emacs arg t))
3.147
3.148 (provide 'util)
3.149 ;; util.el ends here