From ef4e4bd51cb9575ec63d16b131d8c9569427e12d Mon Sep 17 00:00:00 2001 From: Eshel Yaron Date: Mon, 8 May 2023 13:28:05 +0300 Subject: [PATCH] Update Emacs configuration --- .emacs.d/init.el | 159 +++++++++++++++++++++++++++++++++++------------ 1 file changed, 119 insertions(+), 40 deletions(-) diff --git a/.emacs.d/init.el b/.emacs.d/init.el index f7c88c9..0c86462 100644 --- a/.emacs.d/init.el +++ b/.emacs.d/init.el @@ -183,6 +183,8 @@ org-use-fast-todo-selection 'expert ;; set up a group of mutual exclusive tags org-tag-alist '((:startgroup) + ("adi" . ?a) + ("holland" . ?h) ("work" . ?w) ("studies" . ?s) ("esols" . ?e) @@ -215,12 +217,24 @@ org-refile-use-outline-path t ;; archive for Org entries org-archive-location "~/org/journal.org::datetree/* Finished Tasks :ARCHIVE:" + ;; associate Org Babel languages with major modes + org-src-lang-modes '(("SWI-Prolog" . sweeprolog) + ("Dockerfile" . dockerfile-ts) + ("bash" . sh) + ("shell" . sh) + ("toml" . toml-ts)) ;; don't auto-save remote files remote-file-name-inhibit-auto-save t ;; don't ask me about it either tramp-allow-unsafe-temporary-files t ;; increase maximum number of recent files Emacs remembers recentf-max-saved-items 128 + ;; increase maximum kill ring size + kill-ring-max 256 + ;; save text copied from another program to the kill ring + save-interprogram-paste-before-kill 2048 + ;; have C-u followed by repeated C-SPC keep popping + set-mark-command-repeat-pop t ;; enable italic text in code modus-themes-italic-constructs t ;; enable bold text in code @@ -260,16 +274,25 @@ "mail.eshelyaron.com" 587 "me@eshelyaron.com" - starttls nil nil nil))) + starttls nil nil nil)) + ;; (uva . ("eshel.yaron@student.uva.nl" + ;; "smtp.office365.com" + ;; 587 + ;; "eshel.yaron@student.uva.nl" + ;; starttls nil nil nil)) + ) ;; associate email addresses with SMTP accounts - smtpmail-multi-associations '(("[^z-a]*eshelshay\\.yaron@gmail\\.com[^z-a]*" esy) - ("[^z-a]*eshel@swi-prolog\\.org[^z-a]*" swp) - ("[^z-a]*me@eshelyaron\\.com[^z-a]*" me)) + smtpmail-multi-associations '(("eshelshay\.yaron@gmail\.com" esy) + ("eshel@swi-prolog\.org" swp) + ("me@eshelyaron\.com" me) + ;; ("eshel\.yaron@student\.uva\.nl" uva) + ) ;; set function for sending email send-mail-function #'smtpmail-multi-send-it message-send-mail-function #'smtpmail-multi-send-it ;; set email user agent mail-user-agent 'gnus-user-agent + read-mail-command 'gnus ;; make Gnus not prompt as much gnus-expert-user t ;; make Gnus read the dribble file on startup without prompting @@ -291,7 +314,12 @@ (nnimap "swi" (nnimap-address "mail.swi-prolog.com") (nnimap-server-port "imaps") - (nnimap-stream ssl))) + (nnimap-stream ssl)) + ;; (nnimap "uva" + ;; (nnimap-address "outlook.office365.com") + ;; (nnimap-server-port "imaps") + ;; (nnimap-stream ssl)) + ) ;; simpler message gnus-no-groups-message "No new articles" ;; don't close other windows when opening Gnus @@ -336,12 +364,13 @@ global-auto-revert-non-file-buffers t auto-revert-verbose nil query-about-changed-file t + ;; show flymake diagnostics as overlays at eol + ;; flymake-show-diagnostics-at-end-of-line t ; not quite there yet kill-do-not-save-duplicates t show-trailing-whitespace t read-extended-command-predicate #'command-completion-default-include-p completions-format 'one-column completion-auto-select nil - completions-detailed nil completion-styles '(orderless partial-completion basic) completion-show-help nil ;; completions-header-format nil @@ -367,7 +396,7 @@ ;; persist Git commit message history savehist-additional-variables '(log-edit-comment-ring) ;; IRC stuff - rcirc-default-nick "eshel" + rcirc-default-nick "esy" rcirc-server-alist '(("irc.libera.chat" :channels ("#emacs") :port 6697 @@ -380,7 +409,16 @@ ;; search dictionaries until one yields a match dictionary-default-dictionary "!" ;; reuse the dictionary buffer - dictionary-use-single-buffer t) + dictionary-use-single-buffer t + ;; have common bindings initially hidden in the output of C-h b + describe-bindings-outline-rules `((match-regexp + . + ,(regexp-opt + '("Key translations" + "Global Bindings" + "Function key map translations" + "pixel-scroll-precision-mode" + "context-menu-mode"))))) (setq-default indent-tabs-mode nil)) (esy/init-step theme @@ -482,7 +520,45 @@ filename)))) (with-eval-after-load 'comint - (keymap-set comint-mode-map "C-c C-q" #'esy/log-buffer))) + (keymap-set comint-mode-map "C-c C-q" #'esy/log-buffer)) + + (defun esy/recent-log-summary () + "Display a summary of my website's most recent access log." + (interactive) + (let ((default-directory "/ssh:root@direct.eshelyaron.com:/var/log/apache2/")) + (async-shell-command (string-join '("grep -E '\"GET.+\" 2' access.log" + "tr -d '\"'" + "tr -d \"'\"" + "cut -f 7,11,12 -d ' '" + "sort" + "uniq -c" + "sort -n") + " | ") + "*Recent Log Summary*"))) + + (defun esy/access-log-summary () + "Display a summary of my website's access log." + (interactive) + (let ((default-directory "/ssh:root@direct.eshelyaron.com:/var/log/apache2/")) + (async-shell-command (string-join '("zcat access.log.*.gz" + "cat - access.log access.log.1" + "grep -E '\"GET.+\" 2'" + "tr -d '\"'" + "tr -d \"'\"" + "cut -f 7,11,12 -d ' '" + "sort" + "uniq -c" + "sort -n") + " | ") + "*Access Log Summary*"))) + + (defun esy/clone (remote) + (interactive "sClone: ") + (vc-clone remote 'Git + (expand-file-name + (file-name-base (car (url-path-and-query + (url-generic-parse-url remote)))) + "~/checkouts")))) (esy/init-step auto-exec-permissions "Ensure scripts ran with `executable-interpret' are executable." @@ -525,10 +601,7 @@ (esy/init-step other-hooks "Extend other standard hooks." - (add-hook 'text-mode-hook #'flyspell-mode) - (add-hook 'completion-list-mode-hook - (lambda () - (setq-local cursor-in-non-selected-windows nil)))) + (add-hook 'text-mode-hook #'flyspell-mode)) (esy/init-step bindings "Bind some keys." @@ -554,7 +627,7 @@ (keymap-global-set " " #'zap-up-to-char) (keymap-global-set " " #'consult-imenu) (keymap-global-set " " #'duplicate-line) - (keymap-global-set "M-#" #'dictionary-lookup-definition) + (keymap-global-set "M-#" #'dict-describe-word) (keymap-global-set "M-o" #'previous-buffer) (keymap-global-set "M-O" #'next-buffer) (keymap-global-set "C-," #'backward-delete-char) @@ -711,9 +784,7 @@ as the initial input for completion, and return that directory." (esy/init-step org "Configure Org mode." (with-eval-after-load 'org - (keymap-unset org-mode-map "C-," t) - (add-to-list 'org-src-lang-modes '(("SWI-prolog" . sweeprolog) - ("bash" . sh)))) + (keymap-unset org-mode-map "C-," t)) (with-eval-after-load 'org-agenda (add-to-list 'org-agenda-custom-commands @@ -745,7 +816,14 @@ as the initial input for completion, and return that directory." "Configure remote access via `tramp'." (with-eval-after-load 'tramp (tramp-set-completion-function "ssh" '((tramp-parse-netrc "~/.authinfo.gpg"))) - (add-to-list 'backup-directory-alist (cons tramp-file-name-regexp nil)))) + (add-to-list 'backup-directory-alist (cons tramp-file-name-regexp nil)) + (define-advice completion-file-name-table (:filter-args (args) no-remote-file-name-completion) + (let ((string (car args)) + (pred (cadr args)) + (action (caddr args))) + (if (and (file-remote-p string) (eq pred #'file-exists-p)) + (list string nil action) + (list string pred action)))))) (esy/init-step proced "Configure `proced'." @@ -767,34 +845,34 @@ as the initial input for completion, and return that directory." (esy/init-step minibuffer-completion "Configure minibuffer completions." - (add-to-list 'display-buffer-alist - '("\\*Completions\\*" - (display-buffer-reuse-window display-buffer-at-bottom) - (window-parameters . ((mode-line-format . none))))) - (define-advice completion-file-name-table (:filter-args (args) no-remote-file-name-completion) - (let ((string (car args)) - (pred (cadr args)) - (action (caddr args))) - (if (and (file-remote-p string) (eq pred #'file-exists-p)) - (list string nil action) - (list string pred action)))) + (defvar esy/completing-read-commands nil) - (keymap-set minibuffer-local-completion-map - "C-p" - #'minibuffer-previous-completion) + (add-to-list 'savehist-additional-variables + 'esy/completing-read-commands) - (keymap-set minibuffer-local-completion-map - "C-n" - #'minibuffer-next-completion) + (define-advice completing-read (:before (&rest _) record-command) + (cl-incf (alist-get this-command esy/completing-read-commands 0))) + + (add-to-list 'display-buffer-alist + '("\\*Completions\\*" + (display-buffer-reuse-window display-buffer-at-bottom) + (window-parameters (mode-line-format . none)))) - (keymap-set minibuffer-local-completion-map - "M-j" - #'minibuffer-force-complete-and-exit) + (add-hook 'completion-list-mode-hook + (lambda () + (setq-local cursor-in-non-selected-windows nil))) + (dolist (key-binding '(("C-p" . minibuffer-previous-completion) + ("C-n" . minibuffer-next-completion) + ("M-j" . minibuffer-force-complete-and-exit))) + (keymap-set minibuffer-local-completion-map + (car key-binding) + (cdr key-binding))) (with-eval-after-load 'marginalia - (add-hook 'marginalia-mode-hook #'all-the-icons-completion-marginalia-setup)) + (add-hook 'marginalia-mode-hook + #'all-the-icons-completion-marginalia-setup)) (with-eval-after-load 'consult (with-eval-after-load 'embark @@ -939,6 +1017,7 @@ as the initial input for completion, and return that directory." (esy/init-step sweep "Configure Prolog integration via `sweeprolog'." + (add-to-list 'major-mode-remap-alist '(prolog-mode . sweeprolog-mode)) (with-eval-after-load 'sweeprolog (add-hook 'sweeprolog-mode-hook #'sweeprolog-electric-layout-mode) (add-hook 'sweeprolog-top-level-mode-hook #'compilation-shell-minor-mode) @@ -967,7 +1046,7 @@ as the initial input for completion, and return that directory." ("\\.rs\\'" . rust-ts-mode) ("\\.go\\'" . go-ts-mode) ("\\.pdf\\'" . pdf-view-mode) - ("\\.plt?\\'" . sweeprolog-mode))) + ("\\.plt?\\'" . prolog-mode))) (push cell auto-mode-alist))) (esy/init-step kill-hook -- 2.39.2