[CMake] Emacs: Addition to cmake-model.el to show cmake documentation
James Bigler
jamesbigler at gmail.com
Tue Apr 28 12:09:56 EDT 2009
On Tue, Apr 28, 2009 at 8:21 AM, Martin Apel <martin.apel at simpack.de> wrote:
> Bill Hoffman wrote:
>> Martin Apel wrote:
>>
>>> Hi all,
>>>
>>> Inspired by the Emacs command cperl-perldoc-at-point I wrote a little
>>> command to show the CMake documentation of the command on which the
>>> cursor is currently positioned. It will open another buffer and show the
>>> documentation generated from "cmake --help-command <command>" in that
>>> buffer. I found it very useful during creating CMakeLists.txt files.
>>>
>>> Bill, maybe it makes sense to integrate this into cmake-mode.el?
>>>
>>>
>>
>> Looks neat. Is there a better way in emacs to set the path to CMake?
>> On many systems I do not put cmake into the PATH.
>>
>> -Bill
>>
>>
> You could probably make it a variable, which would be settable through
> the customize interface of Emacs. I will look into it
> and repost it, when it's done.
>
> Martin
>
This is pretty lean. I wrote something similar that I was testing.
Some features:
1. Provides a default argument, but allows you type in something different.
2. Maintains a history of the arguments you have given.
3. Allows you to run an arbitrary cmake command and put the output into a
named buffer.
4. Runs the cmake command in the back.
5. cmake executable is a customized variable.
James
(defun cmake-find-word ()
"Finds the word on your cursor."
(interactive)
(let (word)
(save-excursion
;; Find the end of the word
(forward-word)
(let ((end (point)))
;; Find the beginning
(backward-word)
;; Set the word
(setq word (buffer-substring-no-properties (point) end))
)
)
)
)
(defcustom cmake-mode-cmake-executable "cmake"
"*The name of the cmake executable.
This can be either absolute or looked up on `exec-path'."
;; Don't use (file :must-match t). It doesn't know about `exec-path'.
:type 'file
:group 'cmake)
(defun cmake-command-run (type &optional topic)
"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))
)
(if buffer
(display-buffer buffer 'not-this-window)
;; Buffer doesn't exist. Create it and fill it
(setq buffer (generate-new-buffer bufname))
(setq command (concat cmake-mode-cmake-executable " " type " " topic))
(message "Running %s" command)
(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)
)
)
)
(defun cmake-help-list-commands ()
"Prints out a list of the cmake commands."
(interactive)
(cmake-command-run "--help-command-list")
)
(defvar cmake-help-command-history nil "Topic read history.")
(defun cmake-get-topic (type)
"Gets the topic from the minibuffer input. The default is the word the
cursor is on."
(interactive)
(let* ((default-entry (cmake-find-word))
(input (read-string
(format "CMake %s (default %s): " type default-entry) ;
prompt
nil ; initial input
'cmake-help-command-history ; command history
default-entry ; default-value
)))
(if (string= input "")
(error "No argument given")
input))
)
(defun cmake-help-command ()
"Prints out the help message corresponding to the command the cursor is
on."
(interactive)
(setq command (cmake-get-topic "command"))
(cmake-command-run "--help-command" (downcase command))
)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.cmake.org/pipermail/cmake/attachments/20090428/b2f32db4/attachment.htm>
More information about the CMake
mailing list