cmake-mode.el: Add auto-completion to cmake-help-command

This commit is contained in:
Philipp Möller 2014-01-29 15:19:06 +01:00 committed by Brad King
parent 2a1314150e
commit 3af47e34b6
1 changed files with 19 additions and 8 deletions

View File

@ -281,7 +281,6 @@ optional argument topic will be appended to the argument list."
(select-window (display-buffer buffer 'not-this-window)) (select-window (display-buffer buffer 'not-this-window))
(cmake-mode) (cmake-mode)
(toggle-read-only t)) (toggle-read-only t))
(setq resize-mini-windows resize-mini-windows-save)
) )
) )
@ -293,18 +292,30 @@ optional argument topic will be appended to the argument list."
) )
(defvar cmake-help-command-history nil "Topic read history.") (defvar cmake-help-command-history nil "Topic read history.")
(defvar cmake-help-commands '() "List of available topics for --help-command.")
(defun cmake-command-list-as-list ()
"Run cmake --help-command-list and return a list where each element is a cmake command."
(let ((temp-buffer-name "*CMake Commands Temporary*"))
(save-window-excursion
(cmake-command-run "--help-command-list" nil temp-buffer-name)
(with-current-buffer temp-buffer-name
(cdr (split-string (buffer-substring-no-properties (point-min) (point-max)) "\n" t)))))
)
(require 'thingatpt) (require 'thingatpt)
;;;###autoload ;;;###autoload
(defun cmake-get-topic (type) (defun cmake-get-command ()
"Gets the topic from the minibuffer input. The default is the word the cursor is on." "Gets the topic from the minibuffer input. The default is the word the cursor is on."
(interactive)
(let* ((default-entry (word-at-point)) (let* ((default-entry (word-at-point))
(input (read-string (input (completing-read
(format "CMake %s (default %s): " type default-entry) ; prompt "CMake command: " ; prompt
nil ; initial input ((lambda ()
(if cmake-help-commands cmake-help-commands
(setq cmake-help-commands (cmake-command-list-as-list))))) ; completions
nil ; predicate
t ; require-match
default-entry ; initial-input
'cmake-help-command-history ; command history 'cmake-help-command-history ; command history
default-entry ; default-value
))) )))
(if (string= input "") (if (string= input "")
(error "No argument given") (error "No argument given")
@ -315,7 +326,7 @@ optional argument topic will be appended to the argument list."
(defun cmake-help-command () (defun cmake-help-command ()
"Prints out the help message corresponding to the command the cursor is on." "Prints out the help message corresponding to the command the cursor is on."
(interactive) (interactive)
(cmake-command-run "--help-command" (downcase (cmake-get-topic "command")) "*CMake Help*")) (cmake-command-run "--help-command" (downcase (cmake-get-command)) "*CMake Help*"))
;;;###autoload ;;;###autoload