ido-describe-fns.el 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. ;;; ido-describe-fns.el --- -*- lexical-binding: t -*-
  2. ;; Copyright (C) 2017 Ryan C. Thompson
  3. ;; Filename: ido-describe-fns.el
  4. ;; Author: Ryan C. Thompson
  5. ;; Created: Tue May 16 18:23:13 2017 (-0400)
  6. ;; Version: 3.17
  7. ;; Package-Requires: ((emacs "26.1") (ido-completing-read+ 3.17))
  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. ;; This package implements ido completion for the new `describe-*'
  15. ;; family of functions. These no longer work with ido-ubiquitous
  16. ;; because they use a function-based collection argument to implement
  17. ;; auto-loading of the file corresponding to the prefix you entered in
  18. ;; order to offer completions of symbols from that file.
  19. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  20. ;;
  21. ;; This program is free software: you can redistribute it and/or modify
  22. ;; it under the terms of the GNU General Public License as published by
  23. ;; the Free Software Foundation, either version 3 of the License, or (at
  24. ;; your option) any later version.
  25. ;;
  26. ;; This program is distributed in the hope that it will be useful, but
  27. ;; WITHOUT ANY WARRANTY; without even the implied warranty of
  28. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  29. ;; General Public License for more details.
  30. ;;
  31. ;; You should have received a copy of the GNU General Public License
  32. ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
  33. ;;
  34. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  35. ;;
  36. ;;; Code:
  37. (defconst ido-describe-fns-version "3.17"
  38. "Currently running version of ido-describe-fns.
  39. Note that when you update ido-describe-fns, this variable may not
  40. be updated until you restart Emacs.")
  41. (require 'ido)
  42. (require 'ido-completing-read+)
  43. ;;;###autoload
  44. (defvar ido-descfns-enable-this-call nil
  45. "If non-nil, then the current call to `ido-completing-read+' is by `ido-descfns-read-from-help-symbol-completion-table'.")
  46. (defvar ido-descfns-orig-predicate nil
  47. "Original predicate from the current completion call.")
  48. ;;;###autoload
  49. (define-minor-mode ido-describe-functions-mode
  50. "Use `ido-completing-read' for `describe-variable' and similar functions.
  51. In particular, it uses ido for any function that uses
  52. `help--symbol-completion-table' as the collection argument to
  53. `completing-read'."
  54. nil
  55. :global t
  56. :group 'ido-ubiquitous)
  57. (defun ido-descfns-maybe-load-prefixes (string)
  58. "Load any files needed to complete the current input.
  59. This function auto-loads new files in the same way as
  60. `help--symbol-completion-table', but without doing any
  61. completion.
  62. Returns non-nil if any new files were loaded."
  63. (let ((old-load-history load-history)
  64. (prefixes (radix-tree-prefixes (help-definition-prefixes) string)))
  65. (help--load-prefixes prefixes)
  66. (not (eq load-history old-load-history))))
  67. (defun ido-descfns-post-self-insert-hook ()
  68. "Maybe load new files and update possible ido completions.
  69. Has no effect unless `ido-descfns-enable-this-call' is non-nil."
  70. (when (and ido-descfns-enable-this-call
  71. (ido-descfns-maybe-load-prefixes ido-text))
  72. (with-no-warnings
  73. (setq ido-cur-list
  74. (all-completions "" obarray ido-descfns-orig-predicate)))))
  75. (defun ido-descfns-setup ()
  76. (add-hook 'post-self-insert-hook #'ido-descfns-post-self-insert-hook)
  77. (add-hook 'minibuffer-exit-hook #'ido-descfns-cleanup))
  78. (defun ido-descfns-cleanup ()
  79. (remove-hook 'post-self-insert-hook #'ido-descfns-post-self-insert-hook)
  80. (remove-hook 'minibuffer-exit-hook #'ido-descfns-cleanup)
  81. (remove-hook 'ido-setup-hook #'ido-descfns-setup))
  82. ;; This advice-based implementation is required for reentrancy
  83. (defadvice ido-completing-read+ (around ido-descfns activate)
  84. (let ((ido-descfns-enable-this-call
  85. (and ido-describe-functions-mode
  86. (eq collection 'help--symbol-completion-table)))
  87. ;; Each call gets its own private copy of these hooks
  88. (ido-setup-hook ido-setup-hook)
  89. (minibuffer-exit-hook minibuffer-exit-hook)
  90. (post-self-insert-hook post-self-insert-hook))
  91. ;; Clean up our copy of the hook in case of recursive completion.
  92. (ido-descfns-cleanup)
  93. (when ido-descfns-enable-this-call
  94. ;; Convert the initial collection into something ido-cr+ will
  95. ;; accept
  96. (setq collection obarray
  97. ido-descfns-orig-predicate predicate)
  98. (add-hook 'ido-setup-hook #'ido-descfns-setup))
  99. ad-do-it
  100. (ido-descfns-cleanup)))
  101. (add-hook 'ido-cr+-before-fallback-hook #'ido-descfns-cleanup)
  102. (provide 'ido-describe-fns)
  103. ;;; ido-describe-fns.el ends here