ido-completing-read+.el 47 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101
  1. ;;; ido-completing-read+.el --- A completing-read-function using ido -*- lexical-binding: t -*-
  2. ;; Copyright (C) 2011-2017 Ryan C. Thompson
  3. ;; Filename: ido-completing-read+.el
  4. ;; Author: Ryan Thompson
  5. ;; Created: Sat Apr 4 13:41:20 2015 (-0700)
  6. ;; Version: 4.1
  7. ;; Package-Requires: ((emacs "24.4") (cl-lib "0.5"))
  8. ;; URL: https://github.com/DarwinAwardWinner/ido-ubiquitous
  9. ;; Keywords: ido, completion, convenience
  10. ;; This file is NOT part of GNU Emacs.
  11. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  12. ;;
  13. ;;; Commentary:
  14. ;; If you use the excellent `ido-mode' for efficient completion of
  15. ;; file names and buffers, you might wonder if you can get ido-style
  16. ;; completion everywhere else too. Well, that's what this package
  17. ;; does! ido-ubiquitous is here to enable ido-style completion for
  18. ;; (almost) every function that uses the standard completion function
  19. ;; `completing-read'.
  20. ;; This package implements the `ido-completing-read+' function, which
  21. ;; is a wrapper for `ido-completing-read'. Importantly, it detects
  22. ;; edge cases that ordinary ido cannot handle and either adjusts them
  23. ;; so ido *can* handle them, or else simply falls back to Emacs'
  24. ;; standard completion instead. Hence, you can safely set
  25. ;; `completing-read-function' to `ido-completing-read+' without
  26. ;; worrying about breaking completion features that are incompatible
  27. ;; with ido.
  28. ;; To use this package, call `ido-ubiquitous-mode' to enable the mode,
  29. ;; or use `M-x customize-variable ido-ubiquitous-mode' it to enable it
  30. ;; permanently. Once the mode is enabled, most functions that use
  31. ;; `completing-read' will now have ido completion. If you decide in
  32. ;; the middle of a command that you would rather not use ido, just use
  33. ;; C-f or C-b at the end/beginning of the input to fall back to
  34. ;; non-ido completion (this is the same shortcut as when using ido for
  35. ;; buffers or files).
  36. ;; Note that `completing-read-default' is a very general function with
  37. ;; many complex behaviors that ido cannot emulate. This package
  38. ;; attempts to detect some of these cases and avoid using ido when it
  39. ;; sees them. So some functions will not have ido completion even when
  40. ;; this mode is enabled. Some other functions have ido disabled in
  41. ;; them because their packages already provide support for ido via
  42. ;; other means (for example, magit). See `M-x describe-variable
  43. ;; ido-cr+-function-blacklist' for more information.
  44. ;; ido-completing-read+ version 4.0 is a major update. The formerly
  45. ;; separate package ido-ubiquitous has been subsumed into
  46. ;; ido-completing-read+, so ido-ubiquitous 4.0 is just a wrapper that
  47. ;; loads ido-completing-read+ and displays a warning about being
  48. ;; obsolete. If you have previously customized ido-ubiquitous, be sure
  49. ;; to check out `M-x customize-group ido-completing-read-plus' after
  50. ;; updating to 4.0 and make sure the new settings are to your liking.
  51. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  52. ;;
  53. ;; This program is free software: you can redistribute it and/or modify
  54. ;; it under the terms of the GNU General Public License as published by
  55. ;; the Free Software Foundation, either version 3 of the License, or (at
  56. ;; your option) any later version.
  57. ;;
  58. ;; This program is distributed in the hope that it will be useful, but
  59. ;; WITHOUT ANY WARRANTY; without even the implied warranty of
  60. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  61. ;; General Public License for more details.
  62. ;;
  63. ;; You should have received a copy of the GNU General Public License
  64. ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
  65. ;;
  66. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  67. ;;
  68. ;;; Code:
  69. (defconst ido-completing-read+-version "4.1"
  70. "Currently running version of ido-completing-read+.
  71. Note that when you update ido-completing-read+, this variable may
  72. not be updated until you restart Emacs.")
  73. (require 'ido)
  74. (require 'cl-lib)
  75. (require 'cus-edit)
  76. ;;; Debug messages
  77. (define-minor-mode ido-cr+-debug-mode
  78. "If non-nil, ido-cr+ will print debug info.
  79. Debug info is printed to the *Messages* buffer."
  80. nil
  81. :global t
  82. :group 'ido-completing-read-plus)
  83. (defsubst ido-cr+--debug-message (format-string &rest args)
  84. (when ido-cr+-debug-mode
  85. (apply #'message (concat "ido-completing-read+: " format-string) args)))
  86. ;;; Ido variables
  87. ;; For unknown reasons, these variables need to be re-declared here to
  88. ;; silence byte-compiler warnings, despite already being declared in
  89. ;; ido.el.
  90. (defmacro define-ido-internal-var (symbol &optional initvalue docstring)
  91. "Declare and initialize an ido internal variable.
  92. This is used to suppress byte-compilation warnings about
  93. reference to free variables when ido-cr+ attempts to access
  94. internal ido variables with no initial value set. Such variables
  95. are originally declared like `(defvar VARNAME)'.
  96. This is a wrapper for `defvar' that supplies a default for the
  97. INITVALUE and DOCSTRING arguments."
  98. `(defvar ,symbol ,initvalue
  99. ,(or docstring
  100. "Internal ido variable.
  101. This variable was originally declared in `ido.el' without an
  102. initial value or docstring. The documentation you're reading
  103. comes from re-declaring it in `ido-completing-read+.el' in order
  104. to suppress some byte-compilation warnings. Setting another
  105. package's variable is not safe in general, but in this case it
  106. should be, because ido always let-binds this variable before
  107. using it, so the initial value shouldn't matter.")))
  108. (define-ido-internal-var ido-context-switch-command)
  109. (define-ido-internal-var ido-cur-list)
  110. (define-ido-internal-var ido-require-match)
  111. ;;;###autoload
  112. (defvar ido-cr+-minibuffer-depth -1
  113. "Minibuffer depth of the most recent ido-cr+ activation.
  114. If this equals the current minibuffer depth, then the minibuffer
  115. is currently being used by ido-cr+, and ido-cr+ feature will be
  116. active. Otherwise, something else is using the minibuffer and
  117. ido-cr+ features will be deactivated to avoid interfering with
  118. the other command.
  119. This is set to -1 by default, since `(minibuffer-depth)' should
  120. never return this value.")
  121. (defvar ido-cr+-assume-static-collection nil
  122. "If non-nil, ido-cr+ will assume that the collection is static.
  123. This is used to avoid unnecessary work in the case where the
  124. collection is a function, since a function collection could
  125. potentially change the set of completion candidates
  126. dynamically.")
  127. (defvar ido-cr+-current-command nil
  128. "Command most recently invoked by `call-interactively'.
  129. This is necessary because `command-execute' and
  130. `call-interactively' do not set `this-command'. Instead, the C
  131. code that calls `command-execute' sets it beforehand, so using
  132. either of those functions directly won't set `this-command'.")
  133. (defvar ido-cr+-dynamic-collection nil
  134. "Stores the collection argument if it is a function.
  135. This allows ido-cr+ to update the set of completion candidates
  136. dynamically.")
  137. (defvar ido-cr+-previous-dynamic-update-texts nil
  138. "Values of `ido-text' for the last few dynamic collection updates.
  139. This is used in `ido-cr+-update-dynamic-collection' as an LRU
  140. cache of recent values of `ido-text' in order to skip re-checking
  141. prefixes of these strings.")
  142. (defvar ido-cr+-dynamic-update-idle-time 0.25
  143. "Time to wait before updating dynamic completion list.")
  144. (defvar ido-cr+-dynamic-update-timer nil
  145. "Idle timer for updating dynamic completion list.")
  146. (defvar ido-cr+-exhibit-pending nil
  147. "This is non-nil after calling `ido-tidy' until the next call to `ido-exhibit'.
  148. Typically this is non-nil while any command is running and nil at all
  149. other times, since those two functions are in `pre-command-hook'
  150. and `post-command-hook' respectively. In particular, this will
  151. generally be nil while running an idle timer.")
  152. (defvar ido-cr+-no-default-action 'prepend-empty-string
  153. "Controls the behavior of ido-cr+ when DEF is nil and REQUIRE-MATCH is non-nil.
  154. Possible values:
  155. - `prepend-empty-string': The empty string will be added to the
  156. front of COLLECTION, making it the default. This is the
  157. standard behavior since it mimics the semantics of
  158. `completing-read-default'.
  159. - `append-empty-string': The empty string will be added to the
  160. end of COLLECTION, thus keeping the original default while
  161. making the empty string available as a completion.
  162. - `nil': No action will be taken.
  163. - Any other value: The value will be interpreted as a 1-argument
  164. function, which will receive the current collection as its
  165. argument and return the collection with any necessary
  166. modifications applied.
  167. This is not meant to be set permanently, but rather let-bound
  168. before calling `ido-completing-read+' under controlled
  169. circumstances.")
  170. (defvar ido-cr+-orig-completing-read-args nil
  171. "Original arguments passed to `ido-completing-read+'.
  172. These are used for falling back to `completing-read-default'.")
  173. (defgroup ido-completing-read-plus nil
  174. "Extra features and compatibility for `ido-completing-read'."
  175. :group 'ido)
  176. (defcustom ido-cr+-fallback-function
  177. ;; Initialize to the current value of `completing-read-function',
  178. ;; unless that is already set to the ido completer, in which case
  179. ;; use `completing-read-default'.
  180. (if (memq completing-read-function
  181. '(ido-completing-read+
  182. ido-completing-read
  183. ;; Current ido-ubiquitous function
  184. completing-read-ido-ubiquitous
  185. ;; Old ido-ubiquitous functions that shouldn't be used
  186. completing-read-ido
  187. ido-ubiquitous-completing-read))
  188. 'completing-read-default
  189. completing-read-function)
  190. "Alternate completing-read function to use when ido is not wanted.
  191. This will be used for functions that are incompatible with ido
  192. or if ido cannot handle the completion arguments. It will also be
  193. used when the user requests non-ido completion manually via C-f
  194. or C-b."
  195. :type '(choice (const :tag "Standard emacs completion"
  196. completing-read-default)
  197. (function :tag "Other function"))
  198. :group 'ido-completing-read-plus)
  199. (defcustom ido-cr+-max-items 30000
  200. "Max collection size to use ido-cr+ on.
  201. If `ido-completing-read+' is called on a collection larger than
  202. this, the fallback completion method will be used instead. To
  203. disable fallback based on collection size, set this to nil."
  204. :type '(choice (const :tag "No limit" nil)
  205. (integer
  206. :tag "Limit" :value 30000
  207. :validate
  208. (lambda (widget)
  209. (let ((v (widget-value widget)))
  210. (if (and (integerp v)
  211. (> v 0))
  212. nil
  213. (widget-put widget :error "This field should contain a positive integer")
  214. widget)))))
  215. :group 'ido-completing-read-plus)
  216. (defcustom ido-cr+-function-blacklist
  217. '(read-file-name-internal
  218. read-buffer
  219. ;; https://github.com/DarwinAwardWinner/ido-ubiquitous/issues/60
  220. todo-add-category
  221. ;; Gnus already supports ido on its own
  222. gnus-emacs-completing-read
  223. gnus-iswitchb-completing-read
  224. grep-read-files
  225. ;; Magit already supports ido on its own
  226. magit-builtin-completing-read
  227. ;; ESS already supports ido on its own
  228. ess-completing-read
  229. ;; https://github.com/DarwinAwardWinner/ido-ubiquitous/issues/39
  230. Info-read-node-name
  231. ;; https://github.com/DarwinAwardWinner/ido-ubiquitous/issues/44
  232. tmm-prompt)
  233. "Functions & commands for which ido-cr+ should be disabled.
  234. Each entry can be either a symbol or a string. A symbol means to
  235. fall back specifically for the named function. A regular
  236. expression means to fall back for any function whose name matches
  237. that regular expression. When ido-cr+ is called through
  238. `completing-read', if any function in the call stack of the
  239. current command matches any of the blacklist entries, ido-cr+
  240. will be disabled for that command. Additionally, if the
  241. collection in the call to `completing-read' matches any of the
  242. blacklist entries, ido-cr+ will be disabled.
  243. Note that using specific function names is generally preferable
  244. to regular expressions, because the associated function
  245. definitions will be compared directly, so if the same function is
  246. called by another name, it should still trigger the fallback. For
  247. regular expressions, only name-based matching is possible."
  248. :group 'ido-completing-read-plus
  249. :type '(repeat (choice (symbol :tag "Function or command name")
  250. (string :tag "Regexp"))))
  251. (defcustom ido-cr+-function-whitelist
  252. nil
  253. "Functions & commands for which ido-cr+ should be enabled.
  254. If this variable is nil, the whitelist will not be used, and
  255. ido-cr+ will be allowed in all functions/commands not listed in
  256. `ido-cr+-function-backlist'.
  257. If this variable is non-nil, ido-cr+'s whitelisting mode will be
  258. enabled, and ido-cr+ will be disabled for *all* functions unless
  259. they match one of the entries. Matching is done in the same
  260. manner as `ido-cr+-function-blacklist', and blacklisting takes
  261. precedence over whitelisting."
  262. :group 'ido-completing-read-plus
  263. :type '(repeat (choice (symbol :tag "Function or command name")
  264. (string :tag "Regexp"))))
  265. ;;;###autoload
  266. (defcustom ido-cr+-replace-completely nil
  267. "If non-nil, replace `ido-completeing-read' completely with ido-cr+.
  268. Enabling this may interfere with or cause errors in other
  269. packages that use `ido-completing-read'. If you discover any such
  270. incompatibilities, please file a bug report at
  271. https://github.com/DarwinAwardWinner/ido-ubiquitous/issues"
  272. :type 'boolean)
  273. ;; Signal used to trigger fallback
  274. (define-error 'ido-cr+-fallback "ido-cr+-fallback")
  275. (defsubst ido-cr+--explain-fallback (arg)
  276. ;; This function accepts a string, or an ido-cr+-fallback
  277. ;; signal.
  278. (when ido-cr+-debug-mode
  279. (when (and (listp arg)
  280. (eq (car arg) 'ido-cr+-fallback))
  281. (setq arg (cadr arg)))
  282. (ido-cr+--debug-message "Falling back to `%s' because %s."
  283. ido-cr+-fallback-function arg)))
  284. ;;;###autoload
  285. (defsubst ido-cr+-active ()
  286. "Returns non-nil if ido-cr+ is currently using the minibuffer."
  287. (>= ido-cr+-minibuffer-depth (minibuffer-depth)))
  288. (defsubst ido-cr+-default-was-provided ()
  289. "Returns non-nil if ido-cr+ was passed a non-nil default argument."
  290. (and (nth 6 ido-cr+-orig-completing-read-args)))
  291. (defun ido-cr+--called-from-completing-read ()
  292. "Returns non-nil if the most recent call to ido-cr+ was from `completing-read'."
  293. (equal (cadr (backtrace-frame 1 'ido-completing-read+))
  294. 'completing-read))
  295. (defmacro ido-cr+-function-is-in-list (fun fun-list &optional list-name)
  296. "Return non-nil if FUN matches an entry in FUN-LIST.
  297. This is used to check for matches to `ido-cr+-function-blacklist'
  298. and `ido-cr+-function-whitelist'.
  299. This is declared as macro only in order to extract the variable
  300. name used for the second argument so it can be used in a debug
  301. message. It should be called as if it were a normal function."
  302. (when (null list-name)
  303. (if (symbolp fun-list)
  304. (setq list-name (symbol-name fun-list))
  305. (setq list-name "list")))
  306. `(cl-loop
  307. for entry in ,fun-list
  308. if (cond
  309. ;; Nil: Never matches anything
  310. ((null entry)
  311. nil)
  312. ;; Symbol: Compare names and function definitions
  313. ((symbolp entry)
  314. (or (eq entry ,fun)
  315. (let ((entry-def (ignore-errors (indirect-function entry)))
  316. (fun-def (ignore-errors (indirect-function ,fun))))
  317. (and
  318. fun-def entry-def
  319. (eq
  320. (indirect-function entry-def)
  321. (indirect-function fun-def))))))
  322. ;; String: Do regexp matching against function name if it is a
  323. ;; symbol
  324. ((stringp entry)
  325. (and (symbolp ,fun)
  326. (string-match-p entry (symbol-name ,fun))))
  327. ;; Anything else: invalid blacklist entry
  328. (t
  329. (ido-cr+--debug-message "Ignoring invalid entry in %s: `%S'" ,list-name entry)
  330. nil))
  331. return entry
  332. ;; If no blacklist entry matches, return nil
  333. finally return nil))
  334. (defun ido-cr+-function-is-blacklisted (fun)
  335. "Return non-nil if FUN is blacklisted.
  336. See `ido-cr+-function-blacklist'."
  337. (ido-cr+-function-is-in-list fun ido-cr+-function-blacklist))
  338. (defun ido-cr+-function-is-whitelisted (fun)
  339. "Return non-nil if FUN is whitelisted.
  340. See `ido-cr+-function-whitelist'."
  341. (or (null ido-cr+-function-whitelist)
  342. (ido-cr+-function-is-in-list fun ido-cr+-function-whitelist)))
  343. ;;;###autoload
  344. (defun ido-completing-read+ (prompt collection &optional predicate
  345. require-match initial-input
  346. hist def inherit-input-method)
  347. "ido-based method for reading from the minibuffer with completion.
  348. See `completing-read' for the meaning of the arguments.
  349. This function is a wrapper for `ido-completing-read' designed to
  350. be used as the value of `completing-read-function'. Importantly,
  351. it detects edge cases that ido cannot handle and uses normal
  352. completion for them."
  353. (let (;; Save the original arguments in case we need to do the
  354. ;; fallback
  355. (ido-cr+-orig-completing-read-args
  356. (list prompt collection predicate require-match
  357. initial-input hist def inherit-input-method))
  358. ;; Need to save this since activating the minibuffer once will
  359. ;; clear out any temporary minibuffer hooks, which need to get
  360. ;; restored before falling back.
  361. (orig-minibuffer-setup-hook minibuffer-setup-hook)
  362. ;; Need just the string part of INITIAL-INPUT
  363. (initial-input-string
  364. (cond
  365. ((consp initial-input)
  366. (car initial-input))
  367. ((stringp initial-input)
  368. initial-input)
  369. ((null initial-input)
  370. "")
  371. (t
  372. (signal 'wrong-type-argument (list 'stringp initial-input)))))
  373. ;; If collection is a function, save it for later, unless
  374. ;; instructed not to
  375. (ido-cr+-dynamic-collection
  376. (when (and (not ido-cr+-assume-static-collection)
  377. (functionp collection))
  378. collection))
  379. ;; If the whitelist is empty, everything is whitelisted
  380. (whitelisted (not ido-cr+-function-whitelist)))
  381. (condition-case sig
  382. (progn
  383. ;; Check a bunch of fallback conditions
  384. (when inherit-input-method
  385. (signal 'ido-cr+-fallback
  386. '("ido cannot handle non-nil INHERIT-INPUT-METHOD")))
  387. (when (bound-and-true-p completion-extra-properties)
  388. (signal 'ido-cr+-fallback
  389. '("ido cannot handle non-nil `completion-extra-properties'")))
  390. ;; Check for black/white-listed collection function
  391. (when (functionp collection)
  392. ;; Blacklist
  393. (when (ido-cr+-function-is-blacklisted collection)
  394. (if (symbolp collection)
  395. (signal 'ido-cr+-fallback
  396. (list (format "collection function `%S' is blacklisted" collection)))
  397. (signal 'ido-cr+-fallback
  398. (list "collection function is blacklisted"))))
  399. ;; Whitelist
  400. (when (and (not whitelisted)
  401. (ido-cr+-function-is-whitelisted collection))
  402. (ido-cr+--debug-message
  403. (if (symbolp collection)
  404. (format "Collection function `%S' is whitelisted" collection)
  405. "Collection function is whitelisted"))
  406. (setq whitelisted t)))
  407. ;; Expand all currently-known completions.
  408. (setq collection
  409. (if ido-cr+-assume-static-collection
  410. (all-completions "" collection predicate)
  411. (ido-cr+-all-dynamic-completions
  412. initial-input-string collection predicate)))
  413. ;; No point in using ido unless there's a collection
  414. (when (and (= (length collection) 0)
  415. (not ido-cr+-dynamic-collection))
  416. (signal 'ido-cr+-fallback '("ido is not needed for an empty collection")))
  417. ;; Check for excessively large collection
  418. (when (and ido-cr+-max-items
  419. (> (length collection) ido-cr+-max-items))
  420. (signal 'ido-cr+-fallback
  421. (list
  422. (format
  423. "there are more than %i items in COLLECTION (see `ido-cr+-max-items')"
  424. ido-cr+-max-items))))
  425. ;; If called from `completing-read', check for
  426. ;; black/white-listed commands/callers
  427. (when (ido-cr+--called-from-completing-read)
  428. ;; Check calling command
  429. (when (ido-cr+-function-is-blacklisted this-command)
  430. (signal 'ido-cr+-fallback
  431. (list "calling command `%S' is blacklisted" this-command)))
  432. (when (and (not whitelisted)
  433. (ido-cr+-function-is-whitelisted this-command))
  434. (ido-cr+--debug-message "Command `%S' is whitelisted" this-command)
  435. (setq whitelisted t))
  436. ;; Also need to check `ido-cr+-current-command'
  437. (when (ido-cr+-function-is-blacklisted ido-cr+-current-command)
  438. (signal 'ido-cr+-fallback
  439. (list "calling command `%S' is blacklisted" ido-cr+-current-command)))
  440. (when (and (not whitelisted)
  441. (ido-cr+-function-is-whitelisted ido-cr+-current-command))
  442. (ido-cr+--debug-message "Command `%S' is whitelisted" ido-cr+-current-command)
  443. (setq whitelisted t))
  444. ;; Check every function in the call stack starting after
  445. ;; `completing-read' until to the first
  446. ;; `funcall-interactively' (for a call from the function
  447. ;; body) or `call-interactively' (for a call from the
  448. ;; interactive form, in which the function hasn't actually
  449. ;; been called yet, so `funcall-interactively' won't be on
  450. ;; the stack.)
  451. (cl-loop for i upfrom 1
  452. for caller = (cadr (backtrace-frame i 'completing-read))
  453. while caller
  454. while (not (memq (indirect-function caller)
  455. '(internal--funcall-interactively
  456. (indirect-function 'call-interactively))))
  457. if (ido-cr+-function-is-blacklisted caller)
  458. do (signal 'ido-cr+-fallback
  459. (list (if (symbolp caller)
  460. (format "calling function `%S' is blacklisted" caller)
  461. "a calling function is blacklisted")))
  462. if (and (not whitelisted)
  463. (ido-cr+-function-is-whitelisted caller))
  464. do (progn
  465. (ido-cr+--debug-message
  466. (if (symbolp caller)
  467. (format "Calling function `%S' is whitelisted" caller)
  468. "A calling function is whitelisted"))
  469. (setq whitelisted t))))
  470. (unless whitelisted
  471. (signal 'ido-cr+-fallback
  472. (list "no functions or commands matched the whitelist for this call")))
  473. ;; In ido, the semantics of "default" are simply "put it at
  474. ;; the front of the list". Furthermore, ido has certain
  475. ;; issues with a non-nil DEF arg. Specifically, it can't
  476. ;; handle list defaults or providing both DEF and
  477. ;; INITIAL-INPUT. So, just pre-process the collection to put
  478. ;; the default(s) at the front and then set DEF to nil in
  479. ;; the call to ido to avoid these issues.
  480. (unless (listp def)
  481. ;; Ensure DEF is a list
  482. (setq def (list def)))
  483. (when def
  484. (setq collection (append def (cl-set-difference collection def
  485. :test #'equal))
  486. def nil))
  487. ;; If DEF was nil and REQUIRE-MATCH was non-nil, then we need to
  488. ;; add the empty string as the first option, because RET on
  489. ;; an empty input needs to return "". (Or possibly we need
  490. ;; to take some other action based on the value of
  491. ;; `ido-cr+-no-default-action'.)
  492. (when (and require-match
  493. ido-cr+-no-default-action
  494. (not (ido-cr+-default-was-provided)))
  495. (cl-case ido-cr+-no-default-action
  496. (nil
  497. ;; Take no action
  498. t)
  499. (prepend-empty-string
  500. (ido-cr+--debug-message "Adding \"\" as the default completion since no default was provided.")
  501. (setq collection (cons "" collection)))
  502. (append-empty-string
  503. (ido-cr+--debug-message "Adding \"\" as a completion option since no default was provided.")
  504. (setq collection (append collection '(""))))
  505. (otherwise
  506. (ido-cr+--debug-message "Running custom action function since no default was provided.")
  507. (setq collection (funcall ido-cr+-no-default-action collection)))))
  508. ;; Check for a specific bug
  509. (when (and ido-enable-dot-prefix
  510. (version< emacs-version "26.1")
  511. (member "" collection))
  512. (signal 'ido-cr+-fallback
  513. '("ido cannot handle the empty string as an option when `ido-enable-dot-prefix' is non-nil; see https://debbugs.gnu.org/cgi/bugreport.cgi?bug=26997")))
  514. ;; Fix ido handling of cons-style INITIAL-INPUT. TODO add a
  515. ;; version check after this bug is fixed:
  516. ;; https://debbugs.gnu.org/cgi/bugreport.cgi?bug=27807
  517. (when (consp initial-input)
  518. (setq initial-input
  519. (cons (car initial-input)
  520. ;; `completing-read' uses 0-based index while
  521. ;; `read-from-minibuffer' uses 1-based index.
  522. (1+ (cdr initial-input)))))
  523. ;; Finally ready to do actual ido completion
  524. (prog1
  525. (let ((ido-cr+-minibuffer-depth (1+ (minibuffer-depth)))
  526. ;; Initialize dynamic update vars
  527. (ido-cr+-previous-dynamic-update-texts
  528. (list initial-input-string))
  529. (ido-cr+-dynamic-update-timer nil)
  530. (ido-cr+-exhibit-pending t)
  531. ;; Reset these for the next call to ido-cr+
  532. (ido-cr+-no-default-action 'prepend-empty-string)
  533. (ido-cr+-assume-static-collection nil))
  534. (unwind-protect
  535. (ido-completing-read
  536. prompt collection
  537. predicate require-match initial-input hist def
  538. inherit-input-method)
  539. (when ido-cr+-dynamic-update-timer
  540. (cancel-timer ido-cr+-dynamic-update-timer)
  541. (setq ido-cr+-dynamic-update-timer nil))))
  542. ;; This detects when the user triggered fallback mode
  543. ;; manually.
  544. (when (eq ido-exit 'fallback)
  545. (signal 'ido-cr+-fallback '("user manually triggered fallback")))))
  546. ;; Handler for ido-cr+-fallback signal
  547. (ido-cr+-fallback
  548. (let (;; Reset `minibuffer-setup-hook' to original value
  549. (minibuffer-setup-hook orig-minibuffer-setup-hook)
  550. ;; Reset these for the next call to ido-cr+
  551. (ido-cr+-no-default-action 'prepend-empty-string)
  552. (ido-cr+-assume-static-collection nil))
  553. (ido-cr+--explain-fallback sig)
  554. (apply ido-cr+-fallback-function ido-cr+-orig-completing-read-args))))))
  555. ;;;###autoload
  556. (defun ido-completing-read@ido-cr+-replace (orig-fun &rest args)
  557. "This advice allows ido-cr+ to completely replace `ido-completing-read'.
  558. See the varaible `ido-cr+-replace-completely' for more information."
  559. ;; If this advice is autoloaded, then we need to force loading of
  560. ;; the rest of the file so all the variables will be defined.
  561. (when (not (featurep 'ido-completing-read+))
  562. (require 'ido-completing-read+))
  563. (if (or (ido-cr+-active)
  564. (not ido-cr+-replace-completely))
  565. ;; ido-cr+ has either already activated or isn't going to
  566. ;; activate, so just run the function as normal
  567. (apply orig-fun args)
  568. ;; Otherwise, we need to activate ido-cr+.
  569. (apply #'ido-completing-read+ args)))
  570. ;;;###autoload
  571. (advice-add 'ido-completing-read :around
  572. #'ido-completing-read@ido-cr+-replace)
  573. ;;;###autoload
  574. (defun call-interactively@ido-cr+-record-current-command
  575. (orig-fun command &rest args)
  576. "Let-bind the command being interactively called.
  577. See `ido-cr+-current-command' for more information."
  578. (let ((ido-cr+-current-command command))
  579. (apply orig-fun command args)))
  580. ;;;###autoload
  581. (advice-add 'call-interactively :around
  582. #'call-interactively@ido-cr+-record-current-command)
  583. ;; Fallback on magic C-f and C-b
  584. (defun ido-magic-forward-char@ido-cr+-fallback (&rest args)
  585. "Allow falling back in ido-completing-read+."
  586. (when (ido-cr+-active)
  587. ;; `ido-context-switch-command' is already let-bound at this
  588. ;; point.
  589. (setq ido-context-switch-command #'ido-fallback-command)))
  590. (advice-add 'ido-magic-forward-char :before
  591. #'ido-magic-forward-char@ido-cr+-fallback)
  592. (defun ido-magic-backward-char@ido-cr+-fallback (&rest args)
  593. "Allow falling back in ido-completing-read+."
  594. (when (ido-cr+-active)
  595. ;; `ido-context-switch-command' is already let-bound at this
  596. ;; point.
  597. (setq ido-context-switch-command #'ido-fallback-command)))
  598. (advice-add 'ido-magic-backward-char :before
  599. #'ido-magic-backward-char@ido-cr+-fallback)
  600. (defun ido-select-text@ido-cr+-fix-require-match (orig-fun &rest args)
  601. "Fix ido behavior when `require-match' is non-nil.
  602. Standard ido will allow C-j to exit with an incomplete completion
  603. even when `require-match' is non-nil. Ordinary completion does
  604. not allow this. In ordinary completion, RET on an incomplete
  605. match is equivalent to TAB, and C-j selects the first match.
  606. Since RET in ido already selects the first match, this advice
  607. sets up C-j to be equivalent to TAB in the same situation.
  608. This advice only activates if the current ido completion was
  609. called through ido-cr+."
  610. (if (and
  611. ;; Only override C-j behavior if...
  612. ;; We're using ico-cr+
  613. (ido-cr+-active)
  614. ;; Require-match is non-nil
  615. ido-require-match
  616. ;; Current text is incomplete
  617. (not (member ido-text ido-cur-list)))
  618. (progn
  619. (ido-cr+--debug-message
  620. "Overriding C-j behavior for require-match: performing completion instead of exiting with current text. (This might still exit with a match if `ido-confirm-unique-completion' is nil)")
  621. (ido-complete))
  622. (apply orig-fun args)))
  623. (advice-add 'ido-select-text :around
  624. #'ido-select-text@ido-cr+-fix-require-match)
  625. (defun ido-tidy@ido-cr+-set-exhibit-pending (&rest args)
  626. (setq ido-cr+-exhibit-pending t))
  627. (advice-add 'ido-tidy :after 'ido-tidy@ido-cr+-set-exhibit-pending)
  628. (defun ido-exhibit@ido-cr+-clear-exhibit-pending (&rest args)
  629. (setq ido-cr+-exhibit-pending nil))
  630. (advice-add 'ido-exhibit :before 'ido-exhibit@ido-cr+-clear-exhibit-pending)
  631. (cl-defun ido-cr+-all-dynamic-completions
  632. (string collection &optional predicate
  633. &key prev-string (rmdups t))
  634. "Run `all-completions' on every prefix of STRING.
  635. Arguments COLLECTION and PREDICATE are as in `all-completions'.
  636. Note that \"all prefixes\" includes both STRING itself and the
  637. empty string.
  638. If keyword argument RMDUPS is non-nil, call `delete-dups' on the
  639. result before returning. This is the default. You can pass nil
  640. for this argument if the caller is already going to do its own
  641. duplicate removal.
  642. As an optimization, if keyword argument PREV-STRING is non-nil,
  643. then prefixes of STRING that are also prefixes of PREV-STRING
  644. will be skipped. This is used to avoid duplicating work if the
  645. caller already knows about the completions for PREV-STRING.
  646. PREV-STRING can also be a list of previous strings, in which case
  647. all prefixes of all previous strings will be skipped. In
  648. particular, note that if PREV-STRING equals STRING, this function
  649. will return nil.
  650. This function is only useful if COLLECTION is a function that
  651. might return additional completions for certain non-empty strings
  652. that it wouldn't return for the empty string. If COLLECTION is
  653. not a function, this is equivalent to
  654. `(all-completions \"\" COLELCTION PREDICATE)'."
  655. (cond
  656. ;; Dynamic collection.
  657. ((functionp collection)
  658. (let ((prev-strings (if (listp prev-string)
  659. prev-string
  660. (list prev-string)))
  661. (common-prefix-length -1))
  662. ;; Get the length of the longest common prefix, or -1 if no
  663. ;; previous strings.
  664. (cl-loop for ps in prev-strings
  665. for common-prefix = (s-shared-start ps string)
  666. maximize (length common-prefix) into prefix-length
  667. finally do (setq common-prefix-length
  668. (or prefix-length -1)))
  669. ;; Get completions for all prefixes starting after the longest
  670. ;; previous prefix, or starting from "" if no previous prefix.
  671. (cl-loop
  672. with start-index = (1+ common-prefix-length)
  673. ;; This might execute zero times, if common-prefix = string
  674. for i from start-index upto (length string)
  675. append (all-completions
  676. (s-left i string)
  677. collection
  678. predicate)
  679. into completion-list
  680. finally return (when completion-list
  681. (funcall
  682. (if rmdups #'delete-dups #'identity)
  683. completion-list)))))
  684. ;; If COLLECTION is not a function and PREV-STRING is non-nil, then
  685. ;; the caller already has all the possible completions, so return
  686. ;; nil.
  687. (prev-string
  688. nil)
  689. ;; Otherwise, just call `all-completions' on the empty string to
  690. ;; get every possible completions for a static COLLECTION.
  691. (t
  692. (unless prev-string
  693. (all-completions "" collection predicate)))))
  694. (defun ido-cr+-update-dynamic-collection ()
  695. "Update the set of completions for a dynamic collection.
  696. This has no effect unless `ido-cr+-dynamic-collection' is non-nil."
  697. (when (and (ido-cr+-active)
  698. ido-cr+-dynamic-collection)
  699. (let* ((ido-text
  700. (buffer-substring-no-properties (minibuffer-prompt-end)
  701. ido-eoinput))
  702. (predicate (nth 2 ido-cr+-orig-completing-read-args))
  703. (first-match (car ido-matches))
  704. (remembered-new-string nil)
  705. (strings-to-check
  706. ;; If `ido-text' is a prefix of `first-match', then we
  707. ;; only need to check the latter, because that will
  708. ;; implicitly check the former as well.
  709. (cond
  710. ((null first-match)
  711. (list ido-text))
  712. ((and first-match
  713. (s-prefix? ido-text first-match))
  714. (list first-match))
  715. (t
  716. (list ido-text first-match))))
  717. (new-completions
  718. (cl-loop
  719. with checked-strings = '()
  720. for string in strings-to-check
  721. nconc
  722. (ido-cr+-all-dynamic-completions
  723. string ido-cr+-dynamic-collection predicate
  724. :rmdups nil
  725. :prev-string (append checked-strings
  726. ido-cr+-previous-dynamic-update-texts))
  727. into result
  728. collect string into checked-strings
  729. finally return result)))
  730. (when new-completions
  731. ;; Merge new completions into `ido-cur-list'
  732. (setq
  733. ido-cur-list
  734. (delete-dups (nconc ido-cur-list new-completions)))
  735. ;; Ensure that the currently-selected match is still at the head
  736. ;; of the list
  737. (let ((current-match (car ido-matches)))
  738. (when (and current-match (member current-match ido-cur-list))
  739. (setq ido-cur-list (ido-chop ido-cur-list current-match))))
  740. (ido-cr+--debug-message
  741. "Updated completion candidates for dynamic collection because `ido-text' changed to %S. `ido-cur-list' now has %s elements"
  742. ido-text (length ido-cur-list))
  743. ;; Recompute matches with new completions
  744. (setq ido-rescan t)
  745. (ido-set-matches)
  746. ;; Rebuild the completion display unless ido is already planning
  747. ;; to do it anyway
  748. (unless ido-cr+-exhibit-pending
  749. (ido-tidy)
  750. (ido-exhibit)))
  751. ;; Add `ido-text' and/or `first-match' to the list of remembered
  752. ;; previous update texts. This is used to avoid re-computing
  753. ;; completions on previously-seen string prefixes (since those
  754. ;; completions have already been added to `ido-cur-list')
  755. (cl-loop
  756. for new-text in strings-to-check
  757. do
  758. (cond
  759. ;; Common case optimization: if eitehr new element or first
  760. ;; element of list is a prefix of the other, just keep the
  761. ;; longer one.
  762. ((s-prefix? new-text (car ido-cr+-previous-dynamic-update-texts))
  763. nil)
  764. ((s-prefix? (car ido-cr+-previous-dynamic-update-texts) new-text)
  765. (setf (car ido-cr+-previous-dynamic-update-texts) new-text))
  766. ;; General case: just prepend it to the list
  767. (t
  768. (setq remembered-new-string t)
  769. (push new-text ido-cr+-previous-dynamic-update-texts))))
  770. ;; Remove duplicates and trim the list down to the last 5
  771. ;; remembered texts
  772. (when remembered-new-string
  773. (setq
  774. ido-cr+-previous-dynamic-update-texts
  775. ;; Elisp doesn't seem to have a "take first N elements"
  776. ;; function that returns the entire list if it's shorter than
  777. ;; N instead of signaling an error
  778. (cl-loop
  779. with result = '()
  780. with n-taken = 0
  781. for item in ido-cr+-previous-dynamic-update-texts
  782. if (not (member item) result)
  783. collect item into result and
  784. sum 1 into n-taken
  785. if (>= n-taken 5)
  786. return result
  787. finally return result))))))
  788. ;; Always cancel an active timer when this function is called.
  789. (when ido-cr+-dynamic-update-timer
  790. (cancel-timer ido-cr+-dynamic-update-timer)
  791. (setq ido-cr+-dynamic-update-timer nil))
  792. (defun ido-cr+-schedule-dynamic-collection-update ()
  793. "Schedule a dynamic collection update for now or in the future."
  794. (when (and (ido-cr+-active)
  795. ido-cr+-dynamic-collection)
  796. ;; Cancel the previous timer
  797. (when ido-cr+-dynamic-update-timer
  798. (cancel-timer ido-cr+-dynamic-update-timer)
  799. (setq ido-cr+-dynamic-update-timer nil))
  800. (if (<= (length ido-matches) 1)
  801. ;; If we've narrowed it down to zero or one matches, update
  802. ;; immediately.
  803. (ido-cr+-update-dynamic-collection)
  804. ;; If there are still several choices, defer update until idle
  805. (setq ido-cr+-dynamic-update-timer
  806. (run-with-idle-timer (max 0.01 ido-cr+-dynamic-update-idle-time) nil
  807. #'ido-cr+-update-dynamic-collection)))))
  808. (defun ido-cr+-minibuffer-setup ()
  809. "set up minibuffer `post-command-hook' for ido-cr+ "
  810. (when (ido-cr+-active)
  811. (add-hook 'post-command-hook
  812. 'ido-cr+-schedule-dynamic-collection-update)))
  813. (add-hook 'ido-minibuffer-setup-hook
  814. 'ido-cr+-minibuffer-setup)
  815. ;; (defadvice ido-complete (around dynamic activate)
  816. ;; (let ((ido-confirm-unique-completion
  817. ;; (if ido-cr+-dynamic-collection
  818. ;; t
  819. ;; ido-confirm-unique-completion)))
  820. ;; ad-do-it))
  821. ;; Also need to update dynamic collections on TAB, and do so *before*
  822. ;; deciding to exit based on `ido-confirm-unique-completion'
  823. (defun ido-complete@ido-cr+-update-dynamic-collection (oldfun &rest args)
  824. "Maybe update the set of completions when pressing TAB."
  825. (when ido-cr+-dynamic-collection
  826. ;; First run with `ido-confirm-unique-completion' non-nil so it
  827. ;; can't exit
  828. (let ((ido-confirm-unique-completion t))
  829. (apply oldfun args))
  830. ;; Update `ido-eoinput'
  831. (setq ido-eoinput (point-max))
  832. ;; Now do update
  833. (ido-cr+-update-dynamic-collection))
  834. ;; After maybe updating the dynamic collection, if there's still
  835. ;; only one completion, now it's allowed to exit
  836. (apply oldfun args))
  837. (advice-add 'ido-complete :around 'ido-complete@ido-cr+-update-dynamic-collection)
  838. ;; Interoperation with minibuffer-electric-default-mode: only show the
  839. ;; default when the input is empty and the empty string is the
  840. ;; selected choice
  841. (defun minibuf-eldef-update-minibuffer@ido-cr+-compat (orig-fun &rest args)
  842. "This advice allows minibuffer-electric-default-mode to work with ido-cr+."
  843. (if (ido-cr+-active)
  844. (unless (eq minibuf-eldef-showing-default-in-prompt
  845. (and (string= (car ido-cur-list) "")
  846. (string= ido-text "")))
  847. ;; Swap state.
  848. (setq minibuf-eldef-showing-default-in-prompt
  849. (not minibuf-eldef-showing-default-in-prompt))
  850. (overlay-put minibuf-eldef-overlay 'invisible
  851. (not minibuf-eldef-showing-default-in-prompt)))
  852. (apply orig-fun args)))
  853. (advice-add 'minibuf-eldef-update-minibuffer :around
  854. #'minibuf-eldef-update-minibuffer@ido-cr+-compat)
  855. ;;;###autoload
  856. (define-minor-mode ido-ubiquitous-mode
  857. "Use ido completion instead of standard completion almost everywhere.
  858. If this mode causes problems for a function, you can customize
  859. when ido completion is or is not used by customizing
  860. `ido-cr+-function-blacklist'."
  861. nil
  862. :global t
  863. :group 'ido-completing-read-plus
  864. ;; Actually enable/disable the mode by setting
  865. ;; `completing-read-function'.
  866. (setq completing-read-function
  867. (if ido-ubiquitous-mode
  868. #'ido-completing-read+
  869. ido-cr+-fallback-function)))
  870. (defcustom ido-cr+-auto-update-blacklist 'notify
  871. "Whether to add new overrides when updating ido-cr+.
  872. This variable has 3 possible values, with the following meanings:
  873. `t': Auto-update the blacklist
  874. `notify': Notify you about updates but do not apply them
  875. `nil': Ignore all blacklist updates
  876. Ido-cr+ comes with a default blacklist for commands that are
  877. known to be incompatible with ido completion. New versions of
  878. ido-cr+ may come with updates to this blacklist as more
  879. incompatible commands are discovered. However, customizing your
  880. own overrides would normally prevent you from receiving these
  881. updates, since Emacs will not overwrite your customizations.
  882. To resolve this problem, you can set this variable to `t', and
  883. then ido-cr+ can automatically add any new built-in overrides
  884. whenever it is updated. (Actually, the update will happen the
  885. next time Emacs is restarted after the update.) This allows you
  886. to add your own overrides but still receive updates to the
  887. default set.
  888. If you want ido-cr+ to just notify you about new default
  889. overrides instead of adding them itself, set this variable to
  890. `notify'. If you don't want this auto-update behavior at all, set
  891. it to `nil'.
  892. (Note that having this option enabled effectively prevents you
  893. from removing any of the built-in default blacklist entries,
  894. since they will simply be re-added the next time Emacs starts.)"
  895. :type '(choice :tag "When new overrides are available:"
  896. (const :menu-tag "Auto-add"
  897. :tag "Add them automatically"
  898. t)
  899. (const :menu-tag "Notify"
  900. :tag "Notify me about them"
  901. notify)
  902. (const :menu-tag "Ignore"
  903. :tag "Ignore them"
  904. nil))
  905. :group 'ido-completing-read-plus)
  906. (defun ido-cr+-update-blacklist (&optional save quiet)
  907. "Re-add any missing default blacklist entries.
  908. This is useful after an update of ido-ubiquitous that adds new
  909. default overrides. See `ido-cr+-auto-update-blacklist' for more
  910. information.
  911. If SAVE is non-nil, also save the new blacklist to the user's
  912. Custom file (but only if it was already customized beforehand).
  913. When called interactively, a prefix argument triggers a save.
  914. When called from Lisp code, this function returns non-nil if the
  915. blacklist was modified."
  916. (interactive "P")
  917. (let* ((var-state (custom-variable-state 'ido-cr+-function-blacklist
  918. ido-cr+-function-blacklist))
  919. (curval ido-cr+-function-blacklist)
  920. (defval (eval (car (get 'ido-cr+-function-blacklist 'standard-value))))
  921. (newval (delete-dups (append defval curval)))
  922. (new-entries (cl-set-difference defval curval :test #'equal))
  923. (modified nil)
  924. (saved nil)
  925. (message-lines ()))
  926. (cl-case var-state
  927. (standard
  928. ;; Var is not customized, just set the new default
  929. (ido-cr+--debug-message "Blacklist was not customized, so it has been updated to the new default value.")
  930. (setq ido-cr+-function-blacklist defval
  931. modified new-entries))
  932. ((saved set changed)
  933. ;; Var has been customized and saved by the user, so set the
  934. ;; new value and maybe save it
  935. (ido-cr+--debug-message "Updating user-customized blacklist with new default entries.")
  936. (setq ido-cr+-function-blacklist newval
  937. modified t)
  938. (when (and save (eq var-state 'saved))
  939. (ido-cr+--debug-message "Saving new blacklist value to Custom file.")
  940. (customize-save-variable 'ido-cr+-function-blacklist ido-cr+-function-blacklist)
  941. (setq saved t)))
  942. (otherwise
  943. (ido-cr+--debug-message "Customization status of blacklist is unknown. Not modifying it.")))
  944. (if (and modified (not quiet))
  945. (progn
  946. (push (format "Added the following entries to `ido-cr+-function-blacklist': %S" new-entries)
  947. message-lines)
  948. (if saved
  949. (push "Saved the new value of `ido-cr+-function-blacklist' to your Custom file."
  950. message-lines)
  951. (push "However, the new value of `ido-cr+-function-blacklist' has not yet been saved for future sessions. To save it. re-run this command with a prefix argument: `C-u M-x ido-cr+-update-blacklist'; or else manually inspect and save the value using `M-x customize-variable ido-cr+-function-blacklist'."
  952. message-lines)))
  953. (push "No updates were required to `ido-cr+-function-blacklist'." message-lines))
  954. (unless quiet
  955. (message (mapconcat #'identity (nreverse message-lines) "\n")))
  956. modified))
  957. (defun ido-cr+-maybe-update-blacklist ()
  958. "Maybe call `ico-cr+-update-blacklist.
  959. See `ido-cr+-auto-update-blacklist' for more information."
  960. (if ido-cr+-auto-update-blacklist
  961. (let* ((curval ido-cr+-function-blacklist)
  962. (defval (eval (car (get 'ido-cr+-function-blacklist 'standard-value))))
  963. (new-entries (cl-set-difference curval defval :test #'equal)))
  964. (if new-entries
  965. (if (eq ido-cr+-auto-update-blacklist 'notify)
  966. (display-warning 'ido-completing-read+ "There are %s new blacklist entries available. Use `M-x ido-cr+-update-blacklist' to install them. (See `ido-cr+-auto-update-blacklist' for more information.)")
  967. (ido-cr+--debug-message "Initiating blacklist update.")
  968. (ido-cr+-update-blacklist t))
  969. (ido-cr+--debug-message "No blacklist updates available.")))
  970. (ido-cr+--debug-message "Skipping blacklist update by user request.")))
  971. (ido-cr+-maybe-update-blacklist)
  972. (provide 'ido-completing-read+)
  973. ;;; ido-completing-read+.el ends here