summaryrefslogtreecommitdiff
path: root/emacs/inits
diff options
context:
space:
mode:
Diffstat (limited to 'emacs/inits')
-rw-r--r--emacs/inits/11-completion.el27
1 files changed, 22 insertions, 5 deletions
diff --git a/emacs/inits/11-completion.el b/emacs/inits/11-completion.el
index aa12538..de9467e 100644
--- a/emacs/inits/11-completion.el
+++ b/emacs/inits/11-completion.el
@@ -1,4 +1,4 @@
-;; Time-stamp: <2026-01-02 16h17 GMT (d63c23ed)>
+;; Time-stamp: <2026-03-22 11h47 GMT (anker)>
(use-package savehist
:ensure t
@@ -34,22 +34,39 @@
:init
(defun my-completing-read-in-region (start end collection &optional predicate)
"Prompt for completion of region in the minibuffer if non-unique.
- Use as a value for `completion-in-region-function'."
+Use as a value for `completion-in-region-function'."
(let* ((initial (buffer-substring-no-properties start end))
(all (completion-all-completions initial collection predicate
(length initial)))
+ (metadata (completion-metadata initial collection predicate))
+ (exit-fn (completion-metadata-get metadata 'exit-function))
(completion (cond
((atom all) nil)
((and (consp all) (atom (cdr all))) (car all))
(t (completing-read
"Completion: " collection predicate t initial)))))
- (cond (completion (completion--replace start end completion) t)
- (t (message "No completion") nil))))
+ (cond
+ (completion
+ (let* ((bounds (completion-boundaries completion collection nil ""))
+ (prefix-len (car bounds))
+ ;; If completion includes a prefix portion, adjust start
+ (new-start (if (> prefix-len 0)
+ (max start (- end prefix-len))
+ start)))
+ (completion--replace new-start end completion)
+ (when exit-fn
+ (funcall exit-fn completion 'finished)))
+ t)
+ (t (message "No completion") nil))))
(defun my-icomplete-backspace ()
+ "Delete back to previous / in paths, or normal backspace otherwise."
(interactive)
(if (looking-back "[^/]/" (line-beginning-position))
- (backward-kill-word 1)
+ (let ((slash-pos (save-excursion
+ (backward-word 1)
+ (search-backward "/" nil t))))
+ (delete-region (1+ slash-pos) (point)))
(delete-backward-char 1)))
(defun my-switch-to-buffer-with-recentf ()