On Tue, Apr 28, 2009 at 8:21 AM, Martin Apel <<a href="mailto:martin.apel@simpack.de">martin.apel@simpack.de</a>> wrote:<br>> Bill Hoffman wrote:<br>>> Martin Apel wrote:<br>>><br>>>> Hi all,<br>
>>><br>>>> Inspired by the Emacs command cperl-perldoc-at-point I wrote a little<br>>>> command to show the CMake documentation of the command on which the<br>>>> cursor is currently positioned. It will open another buffer and show the<br>
>>> documentation generated from "cmake --help-command <command>" in that<br>>>> buffer. I found it very useful during creating CMakeLists.txt files.<br>>>><br>>>> Bill, maybe it makes sense to integrate this into cmake-mode.el?<br>
>>><br>>>><br>>><br>>> Looks neat. Is there a better way in emacs to set the path to CMake?<br>>> On many systems I do not put cmake into the PATH.<br>>><br>>> -Bill<br>>><br>
>><br>> You could probably make it a variable, which would be settable through<br>> the customize interface of Emacs. I will look into it<br>> and repost it, when it's done.<br>><br>> Martin<br>><br>
<br>This is pretty lean. I wrote something similar that I was testing.<br><br>Some features:<br><br>1. Provides a default argument, but allows you type in something different.<br>2. Maintains a history of the arguments you have given.<br>
3. Allows you to run an arbitrary cmake command and put the output into a named buffer.<br>4. Runs the cmake command in the back.<br>5. cmake executable is a customized variable.<br><br>James<br><br><span style="font-family: courier new,monospace;">(defun cmake-find-word ()</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> "Finds the word on your cursor."</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> (interactive)</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> (let (word)</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> (save-excursion</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> ;; Find the end of the word</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> (forward-word)</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> (let ((end (point)))</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> ;; Find the beginning</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> (backward-word)</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> ;; Set the word</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> (setq word (buffer-substring-no-properties (point) end))</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> )</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> )</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> )</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> )</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">(defcustom cmake-mode-cmake-executable "cmake"<br>
"*The name of the cmake executable.<br>This can be either absolute or looked up on `exec-path'."<br> ;; Don't use (file :must-match t). It doesn't know about `exec-path'.<br> :type 'file<br>
:group 'cmake)<br><br>(defun cmake-command-run (type &optional topic)</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> "Runs the command cmake with the arguments specified. The</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">optional argument topic will be appended to the argument list."</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> (interactive "s")</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> (let* ((bufname (concat "*CMake" type (if topic "-") topic "*"))</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> (buffer (get-buffer bufname))</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> )</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> (if buffer</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> (display-buffer buffer 'not-this-window)</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> ;; Buffer doesn't exist. Create it and fill it</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> (setq buffer (generate-new-buffer bufname))</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> (setq command (concat cmake-mode-cmake-executable " " type " " topic))<br>
</span><span style="font-family: courier new,monospace;"> (message "Running %s" command)</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> (shell-command command buffer)</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> ;; Save the original window, so that we can come back to it later.</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> ;; save-excursion doesn't seem to work for this.</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> (setq window (selected-window))</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> ;; We need to select it so that we can apply special modes to it</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> (select-window (display-buffer buffer 'not-this-window))</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> (cmake-mode)</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> (toggle-read-only t)</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> ;; Restore the original window</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> (select-window window)</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> )</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> )</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> )</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">(defun cmake-help-list-commands ()</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> "Prints out a list of the cmake commands."</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> (interactive)</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> (cmake-command-run "--help-command-list")</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> )</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">(defvar cmake-help-command-history nil "Topic read history.")</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">(defun cmake-get-topic (type)</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> "Gets the topic from the minibuffer input. The default is the word the cursor is on."</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> (interactive)</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> (let* ((default-entry (cmake-find-word))</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> (input (read-string</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> (format "CMake %s (default %s): " type default-entry) ; prompt</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> nil ; initial input</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> 'cmake-help-command-history ; command history</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> default-entry ; default-value</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> )))</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> (if (string= input "")</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> (error "No argument given")</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> input))</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> )</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">(defun cmake-help-command ()</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> "Prints out the help message corresponding to the command the cursor is on."</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> (interactive)</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> (setq command (cmake-get-topic "command"))</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> (cmake-command-run "--help-command" (downcase command))</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> )</span><br>