Thanks for the suggestion. word-at-point works better than my hand rolled code.<br><br>Here's the updated version. I also fixed a slight annoyance where if the help command output was short enough it would print the outout to both the help buffer and the minibuffer.<br>
<br>I'm also open to additional suggestions.<br><br>James<br><br><span style="font-family: courier new,monospace;">(defcustom cmake-mode-cmake-executable "cmake"</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> "*The name of the cmake executable.</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">This can be either absolute or looked up on `exec-path'."</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> ;; Don't use (file :must-match t). It doesn't know about `exec-path'.</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> :type 'file</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> :group 'cmake)</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">(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))</span><br style="font-family: courier new,monospace;"><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;"> ;; We don't want the contents of the shell-command running to the</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> ;; minibuffer, so turn it off. A value of nil means don't automatically</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> ;; resize mini-windows.</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> (setq resize-mini-windows-save resize-mini-windows)</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> (setq resize-mini-windows nil)</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;"> (setq resize-mini-windows resize-mini-windows-save)</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;">(require 'thingatpt)</span><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 (word-at-point))</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 style="font-family: courier new,monospace;"><br><br>On Wed, Apr 29, 2009 at 2:58 AM, Martin Apel <<a href="mailto:martin.apel@simpack.de">martin.apel@simpack.de</a>> wrote:<br>
> Hi James,<br>><br>> your version for showing documentation is surely much nicer than mine.<br>> One minor tip: Instead of your function cmake-find-word you could use<br>> the function word-at-point coming from the package thingatpt, which does<br>
> exactly, what you need. This package is part of the current Emacs<br>> distribution.<br>><br>> Best Regards,<br>><br>> Martin<br>><br>> James Bigler wrote:<br>>> On Tue, Apr 28, 2009 at 8:21 AM, Martin Apel <<a href="mailto:martin.apel@simpack.de">martin.apel@simpack.de</a><br>
>> <mailto:<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<br>
>> 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<br>>> 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<br>
>> 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>>> (defun cmake-find-word ()<br>
>> "Finds the word on your cursor."<br>>> (interactive)<br>>> (let (word)<br>>> (save-excursion<br>>> ;; Find the end of the word<br>>> (forward-word)<br>>> (let ((end (point)))<br>
>> ;; Find the beginning<br>>> (backward-word)<br>>> ;; Set the word<br>>> (setq word (buffer-substring-no-properties (point) end))<br>>> )<br>>> )<br>
>> )<br>>> )<br>>><br>>> (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)<br>
>> "Runs the command cmake with the arguments specified. The<br>>> optional argument topic will be appended to the argument list."<br>>> (interactive "s")<br>>> (let* ((bufname (concat "*CMake" type (if topic "-") topic "*"))<br>
>> (buffer (get-buffer bufname))<br>>> )<br>>> (if buffer<br>>> (display-buffer buffer 'not-this-window)<br>>> ;; Buffer doesn't exist. Create it and fill it<br>
>> (setq buffer (generate-new-buffer bufname))<br>>> (setq command (concat cmake-mode-cmake-executable " " type " "<br>>> topic))<br>>> (message "Running %s" command)<br>
>> (shell-command command buffer)<br>>> ;; Save the original window, so that we can come back to it later.<br>>> ;; save-excursion doesn't seem to work for this.<br>>> (setq window (selected-window))<br>
>> ;; We need to select it so that we can apply special modes to it<br>>> (select-window (display-buffer buffer 'not-this-window))<br>>> (cmake-mode)<br>>> (toggle-read-only t)<br>
>> ;; Restore the original window<br>>> (select-window window)<br>>> )<br>>> )<br>>> )<br>>><br>>> (defun cmake-help-list-commands ()<br>>> "Prints out a list of the cmake commands."<br>
>> (interactive)<br>>> (cmake-command-run "--help-command-list")<br>>> )<br>>><br>>> (defvar cmake-help-command-history nil "Topic read history.")<br>>><br>>> (defun cmake-get-topic (type)<br>
>> "Gets the topic from the minibuffer input. The default is the word<br>>> the cursor is on."<br>>> (interactive)<br>>> (let* ((default-entry (cmake-find-word))<br>>> (input (read-string<br>
>> (format "CMake %s (default %s): " type default-entry)<br>>> ; prompt<br>>> nil ; initial input<br>>> 'cmake-help-command-history ; command history<br>
>> default-entry ; default-value<br>>> )))<br>>> (if (string= input "")<br>>> (error "No argument given")<br>>> input))<br>
>> )<br>
>><br>>><br>>> (defun cmake-help-command ()<br>>> "Prints out the help message corresponding to the command the cursor<br>>> is on."<br>>> (interactive)<br>>> (setq command (cmake-get-topic "command"))<br>
>> (cmake-command-run "--help-command" (downcase command))<br>>> )<br>><br>><br>> --<br>><br>> Martin Apel Tel: 0049 8153 9288-47<br>> Software Architect E-Mail: <a href="mailto:martin.apel@simpack.de">martin.apel@simpack.de</a><br>
><br>> INTEC GmbH Tel: 0049 8153 9288-0<br>> Argelsrieder Feld 13 Fax: 0049 8153 9288-11<br>> 82234 Wessling E-Mail: <a href="mailto:intec@simpack.de">intec@simpack.de</a><br>
> Germany URL: <a href="http://www.simpack.com">http://www.simpack.com</a><br>><br>> ____________<br>> Virus checked by G DATA AntiVirus<br>> Version: AVB 19.313 from 28.04.2009<br>
><br>><br>><br><br>