]> git.eshelyaron.com Git - dotfiles.git/commitdiff
Update Emacs configuration
authorEshel Yaron <me@eshelyaron.com>
Fri, 2 Feb 2024 11:08:13 +0000 (12:08 +0100)
committerEshel Yaron <me@eshelyaron.com>
Fri, 2 Feb 2024 11:08:13 +0000 (12:08 +0100)
.emacs.d/init.el
.emacs.d/theme/esy-theme.el

index 821aab1c1b3fc5d85ba3bf5fb68b95c74b7851ca..71a1338cd025e6dc4724146fb8ea189f75fa4ad4 100644 (file)
@@ -80,7 +80,6 @@
   (add-to-list 'load-path (if (file-exists-p build) build repo))
   (unless (file-exists-p repo)
     (make-directory repo t)
-    (when (< emacs-major-version 28) (require 'subr-x))
     (condition-case-unless-debug err
         (if-let ((buffer (pop-to-buffer-same-window "*elpaca-bootstrap*"))
                  ((zerop (call-process "git" nil buffer t "clone"
                      ("install-info" "--dir=dir" "eat.info"))))
 (elpaca (elfeed
          :pre-build (("pandoc" "-o" "elfeed.texi" "README.md"))))
-(elpaca embark)
 (elpaca emms)
 (elpaca htmlize)
-(elpaca keycast)
 (elpaca kubernetes)
 (elpaca (oauth2
          :repo "git://git.sv.gnu.org/emacs/elpa"
                       "--eval" "(setq org-babel-confirm-evaluate-answer-no t)"
                       "-f" "org-texinfo-export-to-texinfo"))))
 (elpaca (openai :repo "https://git.sr.ht/~eshel/openai.el"))
-(elpaca package-lint)
 (elpaca paredit)
 (elpaca rainbow-delimiters)
 (elpaca rainbow-mode)
@@ -384,7 +380,9 @@ DEADLINE: %(format-time-string \"<%Y-%m-%d %H:%M>\" (org-read-date t t))
  ;; follow links to version-controlled files without confirming
  vc-follow-symlinks t
  ;; jump from .c to .h files with find-sibling-file
- find-sibling-rules '(("\\([^/]+\\)\\.c\\'" "\\1.h"))
+ find-sibling-rules '(("\\([^/]+\\)\\.c\\'" "\\1.h")
+                      ("nextstep/Emacs.app/Contents/Resources/\\(.*\\)\\'"
+                       "\\1\\'"))
  ;; use ISO format for calendar dates
  calendar-date-style 'iso
  ;; maintain legibility of rendered text in HTML mails
@@ -421,14 +419,18 @@ DEADLINE: %(format-time-string \"<%Y-%m-%d %H:%M>\" (org-read-date t t))
  kill-do-not-save-duplicates t
  show-trailing-whitespace t
  read-extended-command-predicate #'command-completion-default-include-p
- completions-format 'one-column
+ completions-format 'horizontal
+ completions-group t
  completions-detailed t
  completion-auto-select nil
  completion-styles '(substring partial-completion)
- completion-category-overrides '((buffer (styles substring))
-                                 (file   (styles basic
-                                                 partial-completion
-                                                 substring)))
+ completion-category-overrides
+ '((buffer       (styles                          substring))
+   (file         (styles basic partial-completion substring))
+   (project-file (styles basic partial-completion substring))
+   (recent-file  (styles basic partial-completion substring))
+   (command      (display-sort-function . minibuffer-sort-by-history)
+                 (cycle-sort-function   . minibuffer-sort-by-history)))
  completion-show-help nil
  ;; completions-header-format nil
  ;; completion-auto-help 'visible
@@ -440,9 +442,9 @@ DEADLINE: %(format-time-string \"<%Y-%m-%d %H:%M>\" (org-read-date t t))
  shell-kill-buffer-on-exit t
  compilation-scroll-output t
  display-time-default-load-average nil
- ;; allow disabling confirming before compilation via local variables
+ ;; allow disabling confirming before compilation via local variables foo bar baz
  safe-local-variable-values '((compilation-read-command . nil))
- xref-search-program             'ripgrep
+ xref-search-program 'ripgrep
  ;; include CWD in shell command prompts
  shell-command-prompt-show-cwd t
  sqlformat-command 'pgformatter
@@ -478,8 +480,9 @@ DEADLINE: %(format-time-string \"<%Y-%m-%d %H:%M>\" (org-read-date t t))
  LaTeX-electric-left-right-brace t
  ;; Read remote man pages
  Man-support-remote-systems t
- confirm-nonexistent-file-or-buffer t
- extended-command-dim-hyphens t)
+ ;; confirm-nonexistent-file-or-buffer nil
+ extended-command-dim-hyphens t
+ read-buffer-completion-ignore-case t)
 
 (setq-default indent-tabs-mode nil)
 
@@ -869,7 +872,6 @@ Interactively, POINT is point and KILL is the prefix argument."
 (keymap-global-set "M-o" #'previous-buffer)
 (keymap-global-set "M-O" #'next-buffer)
 (keymap-global-set "C-," #'delete-backward-char)
-(keymap-global-set "C-." #'embark-act)
 (keymap-global-set "C-;" #'avy-goto-char-timer)
 (keymap-global-set "C-s-f" #'toggle-frame-fullscreen)
 (keymap-global-set "C-s-l" #'esy/pulse-line)
@@ -879,6 +881,7 @@ Interactively, POINT is point and KILL is the prefix argument."
 (keymap-global-set "M-]" #'up-list)
 
 (keymap-set ctl-x-map "C-b" #'ibuffer)
+(keymap-set ctl-x-map "k" #'esy/kill-buffers)
 
 (keymap-set search-map "r" #'rg)
 (keymap-set search-map "l" #'rg-literal)
@@ -1076,8 +1079,7 @@ as the initial input for completion, and return that directory."
 
 (dolist (key-binding '(("C-p" . minibuffer-previous-completion)
                        ("C-n" . minibuffer-next-completion)
-                       ("M-j" . minibuffer-force-complete-and-exit)
-                       ("SPC" . nil)))
+                       ("M-j" . minibuffer-force-complete-and-exit)))
   (keymap-set minibuffer-local-completion-map
               (car key-binding)
               (cdr key-binding)))
@@ -1134,6 +1136,7 @@ as the initial input for completion, and return that directory."
                 completions-auto-update-mode
                 global-corfu-mode
                 mode-face-global-mode
+                which-function-mode
                 ))
   (funcall mode))
 
@@ -1216,7 +1219,7 @@ as the initial input for completion, and return that directory."
                 ("\\.rs\\'"    . rust-ts-mode)
                 ("\\.go\\'"    . go-ts-mode)
                 ("\\.plt?\\'"  . prolog-mode)
-                ("\\.tex\\'"   . TeX-latex-mode)))
+                ("\\.tex\\'"   . LaTeX-mode)))
   (push cell auto-mode-alist))
 
 ;;; Configure Help
@@ -1307,6 +1310,9 @@ as the initial input for completion, and return that directory."
 
 ;;; Configure TeX
 
+(with-eval-after-load 'tex-mode
+  (require 'tex))
+
 (with-eval-after-load 'tex
   (setopt TeX-modes '(tex-mode plain-tex-mode latex-mode doctex-mode))
   (add-hook 'plain-TeX-mode-hook
@@ -1330,7 +1336,8 @@ as the initial input for completion, and return that directory."
   (keymap-set LaTeX-mode-map "C-c C-SPC" #'LaTeX-mark-math))
 
 (with-eval-after-load 'elisp-mode
-  (setq elisp-flymake-byte-compile-load-path (cons "./" load-path)))
+  (setq elisp-flymake-byte-compile-load-path (cons "./" load-path))
+  (keymap-set emacs-lisp-mode-map "C-c C-t" #'trace-function))
 
 (dolist (mm '((go-ts-mode         . go-ts-mode-hook)
               (typescript-ts-mode . typescript-ts-mode-hook)
@@ -1371,10 +1378,33 @@ as the initial input for completion, and return that directory."
     (insert (buffer-name buf))
     (exit-minibuffer)))
 
+;; (defun read-buffer-isearch (buffers string)
+;;   (interactive
+;;    (let ((s (minibuffer-contents-no-properties)))
+;;      (list (remove (current-buffer)
+;;                    (seq-filter
+;;                     (lambda (b)
+;;                       (and (buffer-match-p '(not (or (major-mode . messages-buffer-mode)
+;;                                                      (major-mode . fundamental-mode)))
+;;                                            b)
+;;                            (with-current-buffer b
+;;                              (save-excursion
+;;                                (goto-char (point-min))
+;;                                (search-forward s nil t)))))
+;;                     (buffer-list)))
+;;            s))
+;;    minibuffer-mode)
+;;   (unless buffers
+;;     (user-error "No buffers contain `%s'" string))
+;;   (multi-isearch-buffers buffers)
+;;   (isearch-process-search-string string string))
+
 (defvar-keymap read-buffer-to-switch-mode-map
   :doc "Keymap for `read-buffer-to-switch-mode'."
   "M-m" #'read-buffer-to-switch-bookmark
-  "M-r" #'read-buffer-to-switch-recentf)
+  "M-r" #'read-buffer-to-switch-recentf
+  ;; "C-s" #'read-buffer-isearch
+  )
 
 (define-minor-mode read-buffer-to-switch-mode
   "Minor mode for reading a buffer name in the minibuffer."
@@ -1388,9 +1418,72 @@ as the initial input for completion, and return that directory."
     (let ((read-buffer-function nil))
       (read-buffer prompt def require-match predicate))))
 
+(defun esy/kill-buffers (buffers)
+  (interactive
+   (list (let ((def (buffer-name)))
+           (completing-read-multiple
+            (format-prompt "Kill buffers" def)
+            #'completion-buffer-name-table nil t nil
+            'buffer-name-history def))))
+  (when buffers
+    (let ((num (length buffers)))
+      (while (and buffers (kill-buffer (car buffers)))
+        (setq buffers (cdr buffers)))
+      (let* ((spared (length buffers))
+             (killed (- num spared)))
+        (message "Killed %d buffer%s%s."
+                 killed (ngettext "" "s" killed)
+                 (if buffers (format ", %s spared" spared) ""))))))
+
 (setq read-buffer-function #'esy/read-buffer)
 
 (load-file (expand-file-name "admin/cherry.el" source-directory))
 
+(defvar-local minibuffer-hint-timer nil)
+
+(defvar minibuffer-hint-idle-time 1)
+
+(defun minibuffer-hint ()
+  (when-let ((beg-end (minibuffer--completion-boundaries))
+             (beg (car beg-end)) (end (cdr beg-end))
+             (all (let ((completion--input completion--input)
+                        (completion-lazy-hilit t))
+                    (completion-all-sorted-completions beg end))))
+    (let (minibuffer-message-timeout)
+      ;; TODO show number of completions and/or use different face when exact.
+      (minibuffer-message (propertize (car all) 'face 'completions-common-part)))))
+
+(defun minibuffer-hint-cancel-timer ()
+  (when (timerp minibuffer-hint-timer)
+    (cancel-timer minibuffer-hint-timer)
+    (setq minibuffer-hint-timer nil)))
+
+(defun minibuffer-hint-fn (buffer)
+  (lambda ()
+    (when (equal (current-buffer) buffer)
+      (minibuffer-hint))
+    (when (buffer-live-p buffer)
+      (with-current-buffer buffer (minibuffer-hint-cancel-timer)))))
+
+(defun minibuffer-hint-start-timer ()
+  (unless (timerp minibuffer-hint-timer)
+    (setq minibuffer-hint-timer
+          (run-with-idle-timer minibuffer-hint-idle-time
+                               nil (minibuffer-hint-fn (current-buffer))))))
+
+(define-minor-mode minibuffer-hint-mode
+  "Foo."
+  :lighter nil
+  (if minibuffer-hint-mode
+      (progn
+        (add-hook 'post-self-insert-hook #'minibuffer-hint-start-timer nil t)
+        (add-hook 'minibuffer-exit-hook #'minibuffer-hint-cancel-timer nil t))
+    (remove-hook 'post-self-insert-hook #'minibuffer-hint-start-timer t)
+    (minibuffer-hint-cancel-timer)))
+
+(add-hook 'minibuffer-setup-hook (lambda ()
+                                   (when minibuffer-completion-table
+                                     (minibuffer-hint-mode))))
+
 (provide 'init)
 ;;; init.el ends here
index baab475d0feb299674ca363fd35589565a4ed268..47aa6ffa41f001d1f53becb91b87cac5b4f40385 100644 (file)
@@ -47,6 +47,7 @@
      (eglot--managed-mode (" " (:eval (when  (eglot--mode-line-format)))))
      "%n%])"
      (vc-mode vc-mode)
+     (which-func-mode (" " which-func-format))
      mode-line-format-right-align
      (:eval (when (mode-line-window-selected-p)
               (list "" 'display-time-string 'battery-mode-line-string " ")))