Add an :exit-function for completion-at-point.
[bpt/emacs.git] / lisp / comint.el
index 8608c0d..e4bc530 100644 (file)
@@ -3134,19 +3134,20 @@ in the same way as TABLE completes strings of the form (concat S2 S)."
              #'comint--table-subvert
              #'completion-file-name-table
              (cdr prefixes) (car prefixes)))))
-    (list
-     filename-beg filename-end
-     (lambda (string pred action)
-       (let ((completion-ignore-case read-file-name-completion-ignore-case)
-             (completion-ignored-extensions comint-completion-fignore))
-         (if (zerop (length filesuffix))
-             (complete-with-action action table string pred)
-           ;; Add a space at the end of completion.  Use a terminator-regexp
-           ;; that never matches since the terminator cannot appear
-           ;; within the completion field anyway.
-           (completion-table-with-terminator
-            (cons filesuffix "\\`a\\`")
-            table string pred action)))))))
+    (nconc
+     (list
+      filename-beg filename-end
+      (lambda (string pred action)
+        (let ((completion-ignore-case read-file-name-completion-ignore-case)
+              (completion-ignored-extensions comint-completion-fignore))
+          (complete-with-action action table string pred))))
+     (unless (zerop (length filesuffix))
+       (list :exit-function
+             (lambda (_s finished)
+               (when (memq finished '(sole finished))
+                 (if (looking-at (regexp-quote filesuffix))
+                     (goto-char (match-end 0))
+                   (insert filesuffix)))))))))
 
 (defun comint-dynamic-complete-as-filename ()
   "Dynamically complete at point as a filename.