Merge topic 'emacs-mode-enhance'

3af47e34 cmake-mode.el: Add auto-completion to cmake-help-command
2a131415 cmake-mode.el: Clean up cmake-command-run and add buffername argument
This commit is contained in:
Brad King 2014-02-03 11:11:01 -05:00 committed by CMake Topic Stage
commit 05e49057e3
1 changed files with 30 additions and 36 deletions

View File

@ -266,38 +266,21 @@ the indentation. Otherwise it retains the same position on the line"
;;;###autoload
(defun cmake-command-run (type &optional topic)
(defun cmake-command-run (type &optional topic buffer)
"Runs the command cmake with the arguments specified. The
optional argument topic will be appended to the argument list."
(interactive "s")
(let* ((bufname (concat "*CMake" type (if topic "-") topic "*"))
(buffer (get-buffer bufname))
(let* ((bufname (if buffer buffer (concat "*CMake" type (if topic "-") topic "*")))
(buffer (if (get-buffer bufname) (get-buffer bufname) (generate-new-buffer bufname)))
(command (concat cmake-mode-cmake-executable " " type " " topic))
;; Turn of resizing of mini-windows for shell-command.
(resize-mini-windows nil)
)
(if buffer
(display-buffer buffer 'not-this-window)
;; Buffer doesn't exist. Create it and fill it
(let ((buffer (generate-new-buffer bufname))
(command (concat cmake-mode-cmake-executable " " type " " topic))
)
(message "Running %s" command)
;; We don't want the contents of the shell-command running to the
;; minibuffer, so turn it off. A value of nil means don't automatically
;; resize mini-windows.
(setq resize-mini-windows-save resize-mini-windows)
(setq resize-mini-windows nil)
(shell-command command buffer)
;; Save the original window, so that we can come back to it later.
;; save-excursion doesn't seem to work for this.
(setq window (selected-window))
;; We need to select it so that we can apply special modes to it
(select-window (display-buffer buffer 'not-this-window))
(cmake-mode)
(toggle-read-only t)
;; Restore the original window
(select-window window)
(setq resize-mini-windows resize-mini-windows-save)
)
)
(shell-command command buffer)
(save-selected-window
(select-window (display-buffer buffer 'not-this-window))
(cmake-mode)
(toggle-read-only t))
)
)
@ -309,30 +292,41 @@ optional argument topic will be appended to the argument list."
)
(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)
;;;###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."
(interactive)
(let* ((default-entry (word-at-point))
(input (read-string
(format "CMake %s (default %s): " type default-entry) ; prompt
nil ; initial input
(input (completing-read
"CMake command: " ; prompt
((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
default-entry ; default-value
)))
(if (string= input "")
(error "No argument given")
input))
)
;;;###autoload
(defun cmake-help-command ()
"Prints out the help message corresponding to the command the cursor is on."
(interactive)
(cmake-command-run "--help-command" (downcase (cmake-get-topic "command"))))
(cmake-command-run "--help-command" (downcase (cmake-get-command)) "*CMake Help*"))
;;;###autoload