]> git.eshelyaron.com Git - dotfiles.git/commitdiff
Update Emacs configuration
authorEshel Yaron <me@eshelyaron.com>
Sun, 15 Oct 2023 20:46:40 +0000 (22:46 +0200)
committerEshel Yaron <me@eshelyaron.com>
Sun, 15 Oct 2023 20:46:40 +0000 (22:46 +0200)
.emacs.d/init.el
.emacs.d/lisp/completions-auto-update.el [new file with mode: 0644]

index 66768473483f6d85c7193b767e1bb4f353474533..1258eebab3312d89b1d07470f27a6371dd550f4e 100644 (file)
 
 ;;; Install packages
 
+(unless (eq system-type 'android)
+  (elpaca org-transclusion)
+  (elpaca (sweeprolog
+           :repo "~/checkouts/sweep/"
+           :files ("*.org" "*.texi" "sweep.pl"
+                   "sweeprolog-pce-theme.el" "sweeprolog.el"))))
 (elpaca avy)
 (elpaca (bbdb
          :repo "https://git.savannah.nongnu.org/git/bbdb.git"
                      ("mv" "README.texi"  "pdf-tools.texi"))))
 (elpaca ob-prolog)
 
-(unless (eq system-type 'android)
-  (elpaca org)
-  (elpaca org-transclusion)
-  (elpaca (sweeprolog
-           :repo "~/checkouts/sweep/"
-           :files ("*.org" "*.texi" "sweep.pl"
-                   "sweeprolog-pce-theme.el" "sweeprolog.el"))))
-
 (elpaca-wait)
 
 (defvar-keymap esy/elpaca-prefix-map
 
 (add-to-list 'load-path (expand-file-name "lisp/" user-emacs-directory))
 (autoload 'some-button "some-button" nil t)
+(autoload 'completions-auto-update-mode "completions-auto-update" nil t)
 
 (unless (eq system-type 'android)
   (add-to-list 'load-path "~/checkouts/esy-publish/")
@@ -1145,7 +1144,8 @@ 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)))
+                       ("M-j" . minibuffer-force-complete-and-exit)
+                       ("SPC" . nil)))
   (keymap-set minibuffer-local-completion-map
               (car key-binding)
               (cdr key-binding)))
@@ -1223,6 +1223,7 @@ as the initial input for completion, and return that directory."
                 show-paren-mode
                 transient-mark-mode
                 winner-mode
+                completions-auto-update-mode
                 ))
   (funcall mode))
 
diff --git a/.emacs.d/lisp/completions-auto-update.el b/.emacs.d/lisp/completions-auto-update.el
new file mode 100644 (file)
index 0000000..59b4065
--- /dev/null
@@ -0,0 +1,68 @@
+;;; completions-auto-update.el --- Auto-update minibuffer completions  -*- lexical-binding: t; -*-
+
+;; Copyright (C) 2023  Eshel Yaron
+
+;; Author: Eshel Yaron <me@eshelyaron.com>
+;; Keywords: convenience
+
+;; This program is free software; you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+
+;; This program is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with this program.  If not, see <https://www.gnu.org/licenses/>.
+
+;;; Commentary:
+
+;; This file defines a minor mode `completions-auto-update-mode' that
+;; updates the *Completions* buffer as you type in the minibuffer.
+
+;;; Code:
+
+(defcustom completions-auto-update-idle-time 0.2
+  "Number of seconds of idle to wait for before updating *Completions*."
+  :group 'minibuffer
+  :type 'number)
+
+(defvar-local completions-auto-update-timer nil)
+
+(defun completions-auto-update ()
+  "Update the *Completions* buffer, if it is visible."
+  (when (get-buffer-window "*Completions*")
+    (if completion-in-region-mode
+        (completion-help-at-point)
+      (minibuffer-completion-help)))
+  (setq completions-auto-update-timer nil))
+
+(defun completions-auto-update-start-timer ()
+  "Start an idle timer for updating *Completions*."
+  (unless (or completions-auto-update-timer
+              (not (get-buffer-window "*Completions*")))
+    (setq completions-auto-update-timer
+          (run-with-idle-timer completions-auto-update-idle-time
+                               nil #'completions-auto-update))))
+
+(defun completions-auto-update-setup ()
+  (add-hook 'post-self-insert-hook #'completions-auto-update-start-timer nil t))
+
+(defun completions-auto-update-exit ()
+  (remove-hook 'post-self-insert-hook #'completions-auto-update-start-timer t))
+
+(define-minor-mode completions-auto-update-mode
+  "Update the *Completions* buffer as you type in the minibuffer."
+  :global t :group 'minibuffer
+  (if completions-auto-update-mode
+      (progn
+        (add-hook 'minibuffer-setup-hook #'completions-auto-update-setup)
+        (add-hook 'minibuffer-setup-exit #'completions-auto-update-exit))
+    (remove-hook 'minibuffer-setup-hook #'completions-auto-update-setup)
+    (remove-hook 'minibuffer-setup-exit #'completions-auto-update-exit)))
+
+(provide 'completions-auto-update)
+;;; completions-auto-update.el ends here