ido-describe-fns.el 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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") (ido-completing-read+ 3.17) (ido-ubiquitous 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 is an extension for ido-ubiquitous that implements ido
  15. ;; completion for the new `describe-*' family of commands. In recent
  16. ;; Emacs versions, these commands no longer work with ido-ubiquitous
  17. ;; because they now use a function-based collection argument to
  18. ;; implement auto-loading of the file corresponding to the prefix you
  19. ;; entered in order to offer completions of symbols from that file.
  20. ;; Note that there is no separate mode to enable. If
  21. ;; `ido-ubiquitous-mode' is already enabled, then simply loading this
  22. ;; package will enable it as well.
  23. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  24. ;;
  25. ;; This program is free software: you can redistribute it and/or modify
  26. ;; it under the terms of the GNU General Public License as published by
  27. ;; the Free Software Foundation, either version 3 of the License, or (at
  28. ;; your option) any later version.
  29. ;;
  30. ;; This program is distributed in the hope that it will be useful, but
  31. ;; WITHOUT ANY WARRANTY; without even the implied warranty of
  32. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  33. ;; General Public License for more details.
  34. ;;
  35. ;; You should have received a copy of the GNU General Public License
  36. ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
  37. ;;
  38. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  39. ;;
  40. ;;; Code:
  41. (defconst ido-describe-fns-version "3.17"
  42. "Currently running version of ido-describe-fns.
  43. Note that when you update ido-describe-fns, this variable may not
  44. be updated until you restart Emacs.")
  45. (require 'ido)
  46. (require 'ido-completing-read+)
  47. (require 'ido-ubiquitous)
  48. ;;;###autoload
  49. (defvar ido-descfns-enable-this-call nil
  50. "If non-nil, then the current call to `ido-completing-read+' is by `ido-descfns-read-from-help-symbol-completion-table'.")
  51. (defvar ido-descfns-orig-predicate nil
  52. "Original predicate from the current completion call.")
  53. (defun ido-descfns-maybe-load-prefixes (string)
  54. "Load any files needed to complete the current input.
  55. This function auto-loads new files in the same way as
  56. `help--symbol-completion-table', but without doing any
  57. completion.
  58. Returns non-nil if any new files were loaded."
  59. (let ((old-load-history load-history)
  60. (prefixes (radix-tree-prefixes (help-definition-prefixes) string)))
  61. (help--load-prefixes prefixes)
  62. (not (eq load-history old-load-history))))
  63. ;; `ido-exhibit' is the ido post-command hook
  64. (defadvice ido-exhibit (before ido-descfns activate)
  65. "Maybe load new files and update possible ido completions.
  66. Has no effect unless `ido-descfns-enable-this-call' is non-nil."
  67. (when (and ido-descfns-enable-this-call
  68. (ido-descfns-maybe-load-prefixes ido-text))
  69. (with-no-warnings
  70. (setq ido-cur-list
  71. (all-completions "" obarray ido-descfns-orig-predicate))
  72. (ido-ubiquitous--debug-message "ido-describe-fns loaded new files. `ido-cur-list' now has %i items" (length ido-cur-list)))))
  73. ;; This advice-based implementation is required for reentrancy
  74. (defadvice ido-completing-read+ (around ido-descfns activate)
  75. (let ((ido-descfns-enable-this-call
  76. (and ido-ubiquitous-mode
  77. (eq collection 'help--symbol-completion-table))))
  78. (when ido-descfns-enable-this-call
  79. ;; Convert the initial collection into something ido-cr+ will
  80. ;; accept
  81. (ido-ubiquitous--debug-message "Activating ido-describe-fns")
  82. (setq collection obarray
  83. ido-descfns-orig-predicate predicate))
  84. ad-do-it))
  85. (provide 'ido-describe-fns)
  86. ;;; ido-describe-fns.el ends here