diff --git a/tex.el b/tex.el index 394814e..3b54d79 100644 --- a/tex.el +++ b/tex.el @@ -716,18 +716,57 @@ overlays." edit-utils >= 2.32 for XEmacs."))) (if (fboundp 'completing-read-multiple) - (defun TeX-completing-read-multiple - (prompt table &optional predicate require-match initial-input - hist def inherit-input-method) - "Like `completing-read-multiple' which see. -Ensures that empty input results in nil across different emacs versions." - (let ((result (completing-read-multiple prompt table predicate - require-match initial-input - hist def inherit-input-method))) - (if (equal result '("")) nil result))) + (if (< emacs-major-version 24) + ;; GNU Emacs < 24 + (defun TeX-completing-read-multiple + (prompt table &optional predicate require-match initial-input + hist def inherit-input-method) + "Like `completing-read-multiple' which see. +Ensures that empty input results is nil across different emacs versions." + (let ((result (completing-read-multiple prompt table predicate + require-match initial-input + hist def inherit-input-method))) + (if (equal result '("")) nil result))) + ;; GNU Emacs >= 24 + (defun TeX-completing-read-multiple + (prompt table &optional predicate require-match initial-input + hist def inherit-input-method) + "Like `completing-read-multiple' which see. +Ensures that empty input results is nil across different emacs versions." + ;; Based on implementation in lisp/emacs-lisp/crm.el in Emacs git + ;; revision 327f1f6f6d934e58921179275547b2d09f219f32 (Sun, 17 Mar 2013 + ;; 00:19:09 +0000) + (unwind-protect + (progn + (add-hook 'choose-completion-string-functions + 'crm--choose-completion-string) + (let* ((minibuffer-completion-table #'crm--collection-fn) + (minibuffer-completion-predicate predicate) + ;; see completing_read in src/minibuf.c + (minibuffer-completion-confirm + (unless (eq require-match t) require-match)) + (crm-completion-table table) + (map (if require-match + crm-local-must-match-map + crm-local-completion-map)) + ;; If the user enters empty input, `read-from-minibuffer' + ;; returns the empty string, not DEF. + (input (read-from-minibuffer + prompt initial-input map + nil hist def inherit-input-method)) + resul) + (and def (string-equal input "") (setq input def)) + ;; Make sure to return nil with empty input. + (if (equal (setq result (split-string input crm-separator)) + '("")) + nil + result))) + (remove-hook 'choose-completion-string-functions + 'crm--choose-completion-string)))) + ;; XEmacs (defun TeX-completing-read-multiple - (prompt table &optional predicate require-match initial-input - hist def inherit-input-method) + (prompt table &optional predicate require-match initial-input + hist def inherit-input-method) "Poor mans implementation of Emacs' `completing-read-multiple' for XEmacs. The XEmacs package edit-utils-2.32 includes `crm.el'." (multi-prompt (if (boundp 'crm-separator) crm-separator ",") nil prompt