Commit a2a25d24 authored by Stefan Monnier's avatar Stefan Monnier
Browse files

Add an :exit-function for completion-at-point.

* lisp/minibuffer.el (completion--done): New fun.
(completion--do-completion): Use it.  New arg `expect-exact'.
(minibuffer-complete, minibuffer-complete-word): Don't output message,
since completion--do-completion does it for us now.
(minibuffer-force-complete): Use completion--done and
completion--replace.  Handle sole-completion case with more care.
(minibuffer-complete-and-exit): Use new `expect-exact' arg.
(completion-extra-properties): New var.
(completion-annotate-function): Make obsolete.
(minibuffer-completion-help): Adjust accordingly.
Use completion-list-insert-choice-function.
(completion-at-point, completion-help-at-point):
Bind completion-extra-properties.
(completion-pcm-word-delimiters): Add | (for uniquify, for example).
* lisp/simple.el (completion-list-insert-choice-function): New var.
(completion-setup-function): Preserve it.
(choose-completion): Pay attention to it, shuffle the code a bit.
(choose-completion-string): New arg `insert-function'.

* lisp/textmodes/bibtex.el: Convert to lexical binding.
(bibtex-mode-map): Use completion-at-point.
(bibtex-mode): Use define-derived-mode&completion-at-point-functions.
(bibtex-completion-at-point-function): New fun, from bibtex-complete.
(bibtex-complete): Define as obsolete alias.
(bibtex-complete-internal): Remove.
(bibtex-format-entry): Remove unused sub-group in regexp.
* lisp/shell.el (shell--command-completion-data)
(shell-environment-variable-completion):
* lisp/pcomplete.el (pcomplete-completions-at-point):
* lisp/comint.el (comint--complete-file-name-data): Use :exit-function
instead of completion-table-with-terminator so it also works for
choose-completion.
parent 2df215b5
...@@ -68,9 +68,6 @@ and also when HOME is set to C:\ by default. ...@@ -68,9 +68,6 @@ and also when HOME is set to C:\ by default.
* Changes in Emacs 24.1 * Changes in Emacs 24.1
** Completion in a non-minibuffer now tries to detect the end of completion
and pops down the *Completions* buffer accordingly.
** emacsclient changes ** emacsclient changes
*** New emacsclient argument --parent-id ID can be used to open a *** New emacsclient argument --parent-id ID can be used to open a
...@@ -83,9 +80,18 @@ client frame in parent X window ID, via XEmbed. This works like the ...@@ -83,9 +80,18 @@ client frame in parent X window ID, via XEmbed. This works like the
*** If emacsclient shuts down as a result of Emacs signalling an *** If emacsclient shuts down as a result of Emacs signalling an
error, its exit status is 1. error, its exit status is 1.
** Completion can cycle, depending on completion-cycle-threshold. ** Completion
*** Many packages have been changed to use completion-at-point rather than
their own completion code.
*** Completion in a non-minibuffer now tries to detect the end of completion
and pops down the *Completions* buffer accordingly.
*** Completion can cycle, depending on completion-cycle-threshold.
** `completing-read' can be customized using the new variable *** New completion style `substring'.
*** `completing-read' can be customized using the new variable
`completing-read-function'. `completing-read-function'.
** auto-mode-case-fold is now enabled by default. ** auto-mode-case-fold is now enabled by default.
...@@ -833,6 +839,17 @@ sc.el, x-menu.el, rnews.el, rnewspost.el ...@@ -833,6 +839,17 @@ sc.el, x-menu.el, rnews.el, rnewspost.el
* Lisp changes in Emacs 24.1 * Lisp changes in Emacs 24.1
** Completion
*** New variable completion-extra-properties used to specify extra properties
of the current completion:
- :annotate-function, same as the old completion-annotate-function.
- :exit-function, function to call after completion took place.
*** Functions on completion-at-point-functions can return any of the properties
valid for completion-extra-properties.
*** completion-annotate-function is obsolete.
** `glyphless-char-display' can now distinguish between graphical and ** `glyphless-char-display' can now distinguish between graphical and
text terminal display, via a char-table entry that is a cons cell. text terminal display, via a char-table entry that is a cons cell.
...@@ -909,8 +926,6 @@ argument is supplied (see Trash changes, above). ...@@ -909,8 +926,6 @@ argument is supplied (see Trash changes, above).
** buffer-substring-filters is obsoleted by filter-buffer-substring-functions. ** buffer-substring-filters is obsoleted by filter-buffer-substring-functions.
** New completion style `substring'.
** `facemenu-read-color' is now an alias for `read-color'. ** `facemenu-read-color' is now an alias for `read-color'.
The command `read-color' now requires a match for a color name or RGB The command `read-color' now requires a match for a color name or RGB
triplet, instead of signalling an error if the user provides a invalid triplet, instead of signalling an error if the user provides a invalid
......
2011-05-24 Stefan Monnier <monnier@iro.umontreal.ca>
Add an :exit-function for completion-at-point.
* minibuffer.el (completion--done): New fun.
(completion--do-completion): Use it. New arg `expect-exact'.
(minibuffer-complete, minibuffer-complete-word): Don't output message,
since completion--do-completion does it for us now.
(minibuffer-force-complete): Use completion--done and
completion--replace. Handle sole-completion case with more care.
(minibuffer-complete-and-exit): Use new `expect-exact' arg.
(completion-extra-properties): New var.
(completion-annotate-function): Make obsolete.
(minibuffer-completion-help): Adjust accordingly.
Use completion-list-insert-choice-function.
(completion-at-point, completion-help-at-point):
Bind completion-extra-properties.
(completion-pcm-word-delimiters): Add | (for uniquify, for example).
* simple.el (completion-list-insert-choice-function): New var.
(completion-setup-function): Preserve it.
(choose-completion): Pay attention to it, shuffle the code a bit.
(choose-completion-string): New arg `insert-function'.
* textmodes/bibtex.el: Convert to lexical binding.
(bibtex-mode-map): Use completion-at-point.
(bibtex-mode): Use define-derived-mode&completion-at-point-functions.
(bibtex-completion-at-point-function): New fun, from bibtex-complete.
(bibtex-complete): Define as obsolete alias.
(bibtex-complete-internal): Remove.
(bibtex-format-entry): Remove unused sub-group in regexp.
* shell.el (shell--command-completion-data)
(shell-environment-variable-completion):
* pcomplete.el (pcomplete-completions-at-point):
* comint.el (comint--complete-file-name-data): Use :exit-function
instead of completion-table-with-terminator so it also works for
choose-completion.
2011-05-23 Stefan Monnier <monnier@iro.umontreal.ca> 2011-05-23 Stefan Monnier <monnier@iro.umontreal.ca>
* <lots-of-files>.el: Don't quote lambda expressions with `quote'. * <lots-of-files>.el: Don't quote lambda expressions with `quote'.
......
...@@ -3134,19 +3134,20 @@ in the same way as TABLE completes strings of the form (concat S2 S)." ...@@ -3134,19 +3134,20 @@ in the same way as TABLE completes strings of the form (concat S2 S)."
#'comint--table-subvert #'comint--table-subvert
#'completion-file-name-table #'completion-file-name-table
(cdr prefixes) (car prefixes))))) (cdr prefixes) (car prefixes)))))
(list (nconc
filename-beg filename-end (list
(lambda (string pred action) filename-beg filename-end
(let ((completion-ignore-case read-file-name-completion-ignore-case) (lambda (string pred action)
(completion-ignored-extensions comint-completion-fignore)) (let ((completion-ignore-case read-file-name-completion-ignore-case)
(if (zerop (length filesuffix)) (completion-ignored-extensions comint-completion-fignore))
(complete-with-action action table string pred) (complete-with-action action table string pred))))
;; Add a space at the end of completion. Use a terminator-regexp (unless (zerop (length filesuffix))
;; that never matches since the terminator cannot appear (list :exit-function
;; within the completion field anyway. (lambda (_s finished)
(completion-table-with-terminator (when (memq finished '(sole finished))
(cons filesuffix "\\`a\\`") (if (looking-at (regexp-quote filesuffix))
table string pred action))))))) (goto-char (match-end 0))
(insert filesuffix)))))))))
(defun comint-dynamic-complete-as-filename () (defun comint-dynamic-complete-as-filename ()
"Dynamically complete at point as a filename. "Dynamically complete at point as a filename.
......
This diff is collapsed.
...@@ -527,19 +527,19 @@ Same as `pcomplete' but using the standard completion UI." ...@@ -527,19 +527,19 @@ Same as `pcomplete' but using the standard completion UI."
(funcall pcomplete-norm-func (funcall pcomplete-norm-func
(directory-file-name f)) (directory-file-name f))
pcomplete-seen))))))) pcomplete-seen)))))))
(unless (zerop (length pcomplete-termination-string))
;; 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.
(setq table
(apply-partially #'completion-table-with-terminator
(cons pcomplete-termination-string
"\\`a\\`")
table)))
(when pcomplete-ignore-case (when pcomplete-ignore-case
(setq table (setq table
(apply-partially #'completion-table-case-fold table))) (apply-partially #'completion-table-case-fold table)))
(list beg (point) table :predicate pred)))))) (list beg (point) table
:predicate pred
:exit-function
(unless (zerop (length pcomplete-termination-string))
(lambda (_s finished)
(when (memq finished '(sole finished))
(if (looking-at
(regexp-quote pcomplete-termination-string))
(goto-char (match-end 0))
(insert pcomplete-termination-string)))))))))))
;; I don't think such commands are usable before first setting up buffer-local ;; I don't think such commands are usable before first setting up buffer-local
;; variables to parse args, so there's no point autoloading it. ;; variables to parse args, so there's no point autoloading it.
......
...@@ -1074,12 +1074,15 @@ Returns t if successful." ...@@ -1074,12 +1074,15 @@ Returns t if successful."
(list (list
start end start end
(lambda (string pred action) (lambda (string pred action)
(completion-table-with-terminator (if (string-match "/" string)
" " (lambda (string pred action) (completion-file-name-table string pred action)
(if (string-match "/" string) (complete-with-action action completions string pred)))
(completion-file-name-table string pred action) :exit-function
(complete-with-action action completions string pred))) (lambda (_string finished)
string pred action))))) (when (memq finished '(sole finished))
(if (looking-at " ")
(goto-char (match-end 0))
(insert " ")))))))
;; (defun shell-dynamic-complete-as-command () ;; (defun shell-dynamic-complete-as-command ()
;; "Dynamically complete at point as a command. ;; "Dynamically complete at point as a command.
...@@ -1150,18 +1153,17 @@ Returns non-nil if successful." ...@@ -1150,18 +1153,17 @@ Returns non-nil if successful."
(substring x 0 (string-match "=" x))) (substring x 0 (string-match "=" x)))
process-environment)) process-environment))
(suffix (case (char-before start) (?\{ "}") (?\( ")") (t "")))) (suffix (case (char-before start) (?\{ "}") (?\( ")") (t ""))))
(list (list start end variables
start end :exit-function
(apply-partially (lambda (s finished)
#'completion-table-with-terminator (when (memq finished '(sole finished))
(cons (lambda (comp) (let ((suf (concat suffix
(concat comp (if (file-directory-p
suffix (comint-directory (getenv s)))
(if (file-directory-p "/"))))
(comint-directory (getenv comp))) (if (looking-at (regexp-quote suf))
"/"))) (goto-char (match-end 0))
"\\`a\\`") (insert suf))))))))))
variables))))))
(defun shell-c-a-p-replace-by-expanded-directory () (defun shell-c-a-p-replace-by-expanded-directory ()
......
...@@ -5968,6 +5968,12 @@ Its value is a list of the form (START END) where START is the place ...@@ -5968,6 +5968,12 @@ Its value is a list of the form (START END) where START is the place
where the completion should be inserted and END (if non-nil) is the end where the completion should be inserted and END (if non-nil) is the end
of the text to replace. If END is nil, point is used instead.") of the text to replace. If END is nil, point is used instead.")
(defvar completion-list-insert-choice-function #'completion--replace
"Function to use to insert the text chosen in *Completions*.
Called with 3 arguments (BEG END TEXT), it should replace the text
between BEG and END with TEXT. Expected to be set buffer-locally
in the *Completions* buffer.")
(defvar completion-base-size nil (defvar completion-base-size nil
"Number of chars before point not involved in completion. "Number of chars before point not involved in completion.
This is a local variable in the completion list buffer. This is a local variable in the completion list buffer.
...@@ -6031,26 +6037,30 @@ With prefix argument N, move N items (negative N means move backward)." ...@@ -6031,26 +6037,30 @@ With prefix argument N, move N items (negative N means move backward)."
;; In case this is run via the mouse, give temporary modes such as ;; In case this is run via the mouse, give temporary modes such as
;; isearch a chance to turn off. ;; isearch a chance to turn off.
(run-hooks 'mouse-leave-buffer-hook) (run-hooks 'mouse-leave-buffer-hook)
(let (buffer base-size base-position choice) (with-current-buffer (window-buffer (posn-window (event-start event)))
(with-current-buffer (window-buffer (posn-window (event-start event))) (let ((buffer completion-reference-buffer)
(setq buffer completion-reference-buffer) (base-size completion-base-size)
(setq base-size completion-base-size) (base-position completion-base-position)
(setq base-position completion-base-position) (insert-function completion-list-insert-choice-function)
(save-excursion (choice
(goto-char (posn-point (event-start event))) (save-excursion
(let (beg end) (goto-char (posn-point (event-start event)))
(if (and (not (eobp)) (get-text-property (point) 'mouse-face)) (let (beg end)
(setq end (point) beg (1+ (point)))) (cond
(if (and (not (bobp)) (get-text-property (1- (point)) 'mouse-face)) ((and (not (eobp)) (get-text-property (point) 'mouse-face))
(setq end (1- (point)) beg (point))) (setq end (point) beg (1+ (point))))
(if (null beg) ((and (not (bobp))
(error "No completion here")) (get-text-property (1- (point)) 'mouse-face))
(setq beg (previous-single-property-change beg 'mouse-face)) (setq end (1- (point)) beg (point)))
(setq end (or (next-single-property-change end 'mouse-face) (t (error "No completion here")))
(point-max))) (setq beg (previous-single-property-change beg 'mouse-face))
(setq choice (buffer-substring-no-properties beg end))))) (setq end (or (next-single-property-change end 'mouse-face)
(point-max)))
(let ((owindow (selected-window))) (buffer-substring-no-properties beg end))))
(owindow (selected-window)))
(unless (buffer-live-p buffer)
(error "Destination buffer is dead"))
(select-window (posn-window (event-start event))) (select-window (posn-window (event-start event)))
(if (and (one-window-p t 'selected-frame) (if (and (one-window-p t 'selected-frame)
(window-dedicated-p (selected-window))) (window-dedicated-p (selected-window)))
...@@ -6059,20 +6069,20 @@ With prefix argument N, move N items (negative N means move backward)." ...@@ -6059,20 +6069,20 @@ With prefix argument N, move N items (negative N means move backward)."
(or (window-dedicated-p (selected-window)) (or (window-dedicated-p (selected-window))
(bury-buffer))) (bury-buffer)))
(select-window (select-window
(or (and (buffer-live-p buffer) (or (get-buffer-window buffer 0)
(get-buffer-window buffer 0)) owindow))
owindow)))
(with-current-buffer buffer
(choose-completion-string (choose-completion-string
choice buffer choice buffer
(or base-position (or base-position
(when base-size (when base-size
;; Someone's using old completion code that doesn't know ;; Someone's using old completion code that doesn't know
;; about base-position yet. ;; about base-position yet.
(list (+ base-size (with-current-buffer buffer (field-beginning))))) (list (+ base-size (field-beginning))))
;; If all else fails, just guess. ;; If all else fails, just guess.
(with-current-buffer buffer (list (choose-completion-guess-base-position choice)))
(list (choose-completion-guess-base-position choice))))))) insert-function)))))
;; Delete the longest partial match for STRING ;; Delete the longest partial match for STRING
;; that can be found before POINT. ;; that can be found before POINT.
...@@ -6118,7 +6128,8 @@ the minibuffer; no further functions will be called. ...@@ -6118,7 +6128,8 @@ the minibuffer; no further functions will be called.
If all functions in the list return nil, that means to use If all functions in the list return nil, that means to use
the default method of inserting the completion in BUFFER.") the default method of inserting the completion in BUFFER.")
(defun choose-completion-string (choice &optional buffer base-position) (defun choose-completion-string (choice &optional
buffer base-position insert-function)
"Switch to BUFFER and insert the completion choice CHOICE. "Switch to BUFFER and insert the completion choice CHOICE.
BASE-POSITION, says where to insert the completion." BASE-POSITION, says where to insert the completion."
...@@ -6138,8 +6149,8 @@ BASE-POSITION, says where to insert the completion." ...@@ -6138,8 +6149,8 @@ BASE-POSITION, says where to insert the completion."
;; If BUFFER is a minibuffer, barf unless it's the currently ;; If BUFFER is a minibuffer, barf unless it's the currently
;; active minibuffer. ;; active minibuffer.
(if (and mini-p (if (and mini-p
(or (not (active-minibuffer-window)) (not (and (active-minibuffer-window)
(not (equal buffer (equal buffer
(window-buffer (active-minibuffer-window)))))) (window-buffer (active-minibuffer-window))))))
(error "Minibuffer is not active for completion") (error "Minibuffer is not active for completion")
;; Set buffer so buffer-local choose-completion-string-functions works. ;; Set buffer so buffer-local choose-completion-string-functions works.
...@@ -6151,13 +6162,15 @@ BASE-POSITION, says where to insert the completion." ...@@ -6151,13 +6162,15 @@ BASE-POSITION, says where to insert the completion."
;; and indeed unused. The last used to be `base-size', so we ;; and indeed unused. The last used to be `base-size', so we
;; keep it to try and avoid breaking old code. ;; keep it to try and avoid breaking old code.
choice buffer base-position nil) choice buffer base-position nil)
;; This remove-text-properties should be unnecessary since `choice'
;; comes from buffer-substring-no-properties.
;;(remove-text-properties 0 (lenth choice) '(mouse-face nil) choice)
;; Insert the completion into the buffer where it was requested. ;; Insert the completion into the buffer where it was requested.
(delete-region (or (car base-position) (point)) (funcall (or insert-function completion-list-insert-choice-function)
(or (cadr base-position) (point))) (or (car base-position) (point))
(insert choice) (or (cadr base-position) (point))
(remove-text-properties (- (point) (length choice)) (point) choice)
'(mouse-face nil)) ;; Update point in the window that BUFFER is showing in.
;; Update point in the window that BUFFER is showing in.
(let ((window (get-buffer-window buffer t))) (let ((window (get-buffer-window buffer t)))
(set-window-point window (point))) (set-window-point window (point)))
;; If completing for the minibuffer, exit it with this choice. ;; If completing for the minibuffer, exit it with this choice.
...@@ -6223,10 +6236,13 @@ Called from `temp-buffer-show-hook'." ...@@ -6223,10 +6236,13 @@ Called from `temp-buffer-show-hook'."
0 (or completion-base-size 0))))))) 0 (or completion-base-size 0)))))))
(with-current-buffer standard-output (with-current-buffer standard-output
(let ((base-size completion-base-size) ;Read before killing localvars. (let ((base-size completion-base-size) ;Read before killing localvars.
(base-position completion-base-position)) (base-position completion-base-position)
(insert-fun completion-list-insert-choice-function))
(completion-list-mode) (completion-list-mode)
(set (make-local-variable 'completion-base-size) base-size) (set (make-local-variable 'completion-base-size) base-size)
(set (make-local-variable 'completion-base-position) base-position)) (set (make-local-variable 'completion-base-position) base-position)
(set (make-local-variable 'completion-list-insert-choice-function)
insert-fun))
(set (make-local-variable 'completion-reference-buffer) mainbuf) (set (make-local-variable 'completion-reference-buffer) mainbuf)
(if base-dir (setq default-directory base-dir)) (if base-dir (setq default-directory base-dir))
;; Maybe insert help string. ;; Maybe insert help string.
......
;;; bibtex.el --- BibTeX mode for GNU Emacs ;;; bibtex.el --- BibTeX mode for GNU Emacs -*- lexical-binding: t -*-
;; Copyright (C) 1992, 1994-1999, 2001-2011 Free Software Foundation, Inc. ;; Copyright (C) 1992, 1994-1999, 2001-2011 Free Software Foundation, Inc.
...@@ -204,7 +204,7 @@ See also `bibtex-sort-ignore-string-entries'." ...@@ -204,7 +204,7 @@ See also `bibtex-sort-ignore-string-entries'."
(const entry-class) (const entry-class)
(const t))) (const t)))
(put 'bibtex-maintain-sorted-entries 'safe-local-variable (put 'bibtex-maintain-sorted-entries 'safe-local-variable
'(lambda (a) (memq a '(nil t plain crossref entry-class)))) (lambda (a) (memq a '(nil t plain crossref entry-class))))
(defcustom bibtex-sort-entry-class (defcustom bibtex-sort-entry-class
'(("String") '(("String")
...@@ -968,7 +968,7 @@ Set this variable before loading BibTeX mode." ...@@ -968,7 +968,7 @@ Set this variable before loading BibTeX mode."
(modify-syntax-entry ?\" "\"" st) (modify-syntax-entry ?\" "\"" st)
(modify-syntax-entry ?$ "$$ " st) (modify-syntax-entry ?$ "$$ " st)
(modify-syntax-entry ?% "< " st) (modify-syntax-entry ?% "< " st)
(modify-syntax-entry ?' "w " st) (modify-syntax-entry ?' "w " st) ;FIXME: Not allowed in @string keys.
(modify-syntax-entry ?@ "w " st) (modify-syntax-entry ?@ "w " st)
(modify-syntax-entry ?\\ "\\" st) (modify-syntax-entry ?\\ "\\" st)
(modify-syntax-entry ?\f "> " st) (modify-syntax-entry ?\f "> " st)
...@@ -984,7 +984,7 @@ Set this variable before loading BibTeX mode." ...@@ -984,7 +984,7 @@ Set this variable before loading BibTeX mode."
;; The Key `C-c&' is reserved for reftex.el ;; The Key `C-c&' is reserved for reftex.el
(define-key km "\t" 'bibtex-find-text) (define-key km "\t" 'bibtex-find-text)
(define-key km "\n" 'bibtex-next-field) (define-key km "\n" 'bibtex-next-field)
(define-key km "\M-\t" 'bibtex-complete) (define-key km "\M-\t" 'completion-at-point)
(define-key km "\C-c\"" 'bibtex-remove-delimiters) (define-key km "\C-c\"" 'bibtex-remove-delimiters)
(define-key km "\C-c{" 'bibtex-remove-delimiters) (define-key km "\C-c{" 'bibtex-remove-delimiters)
(define-key km "\C-c}" 'bibtex-remove-delimiters) (define-key km "\C-c}" 'bibtex-remove-delimiters)
...@@ -2018,7 +2018,7 @@ Formats current entry according to variable `bibtex-entry-format'." ...@@ -2018,7 +2018,7 @@ Formats current entry according to variable `bibtex-entry-format'."
;; remove delimiters from purely numerical fields ;; remove delimiters from purely numerical fields
(when (and (memq 'numerical-fields format) (when (and (memq 'numerical-fields format)
(progn (goto-char beg-text) (progn (goto-char beg-text)
(looking-at "\\(\"[0-9]+\"\\)\\|\\({[0-9]+}\\)"))) (looking-at "\"[0-9]+\"\\|{[0-9]+}")))
(goto-char end-text) (goto-char end-text)
(delete-char -1) (delete-char -1)
(goto-char beg-text) (goto-char beg-text)
...@@ -2247,10 +2247,11 @@ applied to the content of FIELD. It is an alist with pairs ...@@ -2247,10 +2247,11 @@ applied to the content of FIELD. It is an alist with pairs
(content (bibtex-text-in-field field bibtex-autokey-use-crossref)) (content (bibtex-text-in-field field bibtex-autokey-use-crossref))
case-fold-search) case-fold-search)
(unless content (setq content "")) (unless content (setq content ""))
(dolist (pattern change-list content) (dolist (pattern change-list)
(setq content (replace-regexp-in-string (car pattern) (setq content (replace-regexp-in-string (car pattern)
(cdr pattern) (cdr pattern)
content t))))) content t)))
content))
(defun bibtex-autokey-get-names () (defun bibtex-autokey-get-names ()
"Get contents of the name field of the current entry. "Get contents of the name field of the current entry.
...@@ -2521,7 +2522,7 @@ for parsing BibTeX keys. If parsing fails, try to set this variable to nil." ...@@ -2521,7 +2522,7 @@ for parsing BibTeX keys. If parsing fails, try to set this variable to nil."
(bibtex-sort-ignore-string-entries t) (bibtex-sort-ignore-string-entries t)
bounds) bounds)
(bibtex-map-entries (bibtex-map-entries
(lambda (key beg end) (lambda (key _beg end)
(if (and abortable (if (and abortable
(input-pending-p)) (input-pending-p))
;; user has aborted by typing a key: return `aborted' ;; user has aborted by typing a key: return `aborted'
...@@ -2714,20 +2715,6 @@ When called interactively, FORCE is t, CURRENT is t if current buffer uses ...@@ -2714,20 +2715,6 @@ When called interactively, FORCE is t, CURRENT is t if current buffer uses
(message "No BibTeX buffers defined"))) (message "No BibTeX buffers defined")))
buffer-list)) buffer-list))
(defun bibtex-complete-internal (completions)
"Complete word fragment before point to longest prefix of COMPLETIONS.
COMPLETIONS is an alist of strings. If point is not after the part
of a word, all strings are listed. Return completion."
;; Return value is used by cleanup functions.
;; Code inspired by `lisp-complete-symbol'.
(let ((beg (save-excursion
(re-search-backward "[ \t{\"]")
(forward-char)
(point)))
(end (point)))
(when (completion-in-region beg end completions)
(buffer-substring beg (point)))))
(defun bibtex-complete-string-cleanup (str compl) (defun bibtex-complete-string-cleanup (str compl)
"Cleanup after inserting string STR. "Cleanup after inserting string STR.
Remove enclosing field delimiters for STR. Display message with Remove enclosing field delimiters for STR. Display message with
...@@ -2941,7 +2928,7 @@ BOUND limits the search." ...@@ -2941,7 +2928,7 @@ BOUND limits the search."
;; Interactive Functions: ;; Interactive Functions:
;;;###autoload ;;;###autoload
(defun bibtex-mode () (define-derived-mode bibtex-mode nil "BibTeX"
"Major mode for editing BibTeX files. "Major mode for editing BibTeX files.
General information on working with BibTeX mode: General information on working with BibTeX mode:
...@@ -2953,7 +2940,7 @@ new entry with the command \\[bibtex-clean-entry]. ...@@ -2953,7 +2940,7 @@ new entry with the command \\[bibtex-clean-entry].
Some features of BibTeX mode are available only by setting the variable Some features of BibTeX mode are available only by setting the variable
`bibtex-maintain-sorted-entries' to non-nil. However, then BibTeX mode `bibtex-maintain-sorted-entries' to non-nil. However, then BibTeX mode
works only with buffers containing valid (syntactical correct) and sorted works only with buffers containing valid (syntactically correct) and sorted
entries. This is usually the case, if you have created a buffer completely entries. This is usually the case, if you have created a buffer completely
with BibTeX mode and finished every new entry with \\[bibtex-clean-entry]. with BibTeX mode and finished every new entry with \\[bibtex-clean-entry].
...@@ -2975,7 +2962,7 @@ the name of a field with \\[bibtex-remove-OPT-or-ALT]. ...@@ -2975,7 +2962,7 @@ the name of a field with \\[bibtex-remove-OPT-or-ALT].
\\[bibtex-remove-delimiters] removes the double-quotes or braces around the text of the current field. \\[bibtex-remove-delimiters] removes the double-quotes or braces around the text of the current field.
\\[bibtex-empty-field] replaces the text of the current field with the default \"\" or {}. \\[bibtex-empty-field] replaces the text of the current field with the default \"\" or {}.
\\[bibtex-find-text] moves point to the end of the current field. \\[bibtex-find-text] moves point to the end of the current field.
\\[bibtex-complete] completes word fragment before point according to context. \\[completion-at-point] completes word fragment before point according to context.
The command \\[bibtex-clean-entry] cleans the current entry, i.e. it removes OPT/ALT The command \\[bibtex-clean-entry] cleans the current entry, i.e. it removes OPT/ALT
from the names of all non-empty optional or alternative fields, checks that from the names of all non-empty optional or alternative fields, checks that
...@@ -2993,12 +2980,8 @@ Entry to BibTeX mode calls the value of `bibtex-mode-hook' ...@@ -2993,12 +2980,8 @@ Entry to BibTeX mode calls the value of `bibtex-mode-hook'
if that value is non-nil. if that value is non-nil.
\\{bibtex-mode-map}" \\{bibtex-mode-map}"
(interactive) (add-hook 'completion-at-point-functions
(kill-all-local-variables) 'bibtex-completion-at-point-function nil 'local)
(use-local-map bibtex-mode-map)
(setq major-mode 'bibtex-mode)
(setq mode-name "BibTeX")
(set-syntax-table bibtex-mode-syntax-table)
(make-local-variable 'bibtex-buffer-last-parsed-tick) (make-local-variable 'bibtex-buffer-last-parsed-tick)
;; Install stealthy parse function if not already installed ;; Install stealthy parse function if not already installed
(unless bibtex-parse-idle-timer (unless bibtex-parse-idle-timer
...@@ -3013,9 +2996,8 @@ if that value is non-nil. ...@@ -3013,9 +2996,8 @@ if that value is non-nil.
(set (make-local-variable 'defun-prompt-regexp) "^[ \t]*@[[:alnum:]]+[ \t]*") (set (make-local-variable 'defun-prompt-regexp) "^[ \t]*@[[:alnum:]]+[ \t]*")
(set (make-local-variable 'outline-regexp) "[ \t]*@") (set (make-local-variable 'outline-regexp) "[ \t]*@")
(set (make-local-variable 'fill-paragraph-function) 'bibtex-fill-field) (set (make-local-variable 'fill-paragraph-function) 'bibtex-fill-field)