[CMake] Emacs: Addition to cmake-model.el to show cmake documentation

James Bigler jamesbigler at gmail.com
Wed Apr 29 13:16:08 EDT 2009


Thanks for the suggestion.  word-at-point works better than my hand rolled
code.

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.

I'm also open to additional suggestions.

James

(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)
      ;; 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)
      )
   )
  )

(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.")

(require 'thingatpt)
(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 (word-at-point))
        (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))
  )


On Wed, Apr 29, 2009 at 2:58 AM, Martin Apel <martin.apel at simpack.de> wrote:
> Hi James,
>
> your version for showing documentation is surely much nicer than mine.
> One minor tip: Instead of your function cmake-find-word you could use
> the function word-at-point coming from the package thingatpt, which does
> exactly, what you need. This package is part of the current Emacs
> distribution.
>
> Best Regards,
>
> Martin
>
> James Bigler wrote:
>> On Tue, Apr 28, 2009 at 8:21 AM, Martin Apel <martin.apel at simpack.de
>> <mailto: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))
>>  )
>
>
> --
>
> Martin Apel                                     Tel:     0049 8153 9288-47
> Software Architect                              E-Mail:
martin.apel at simpack.de
>
> INTEC GmbH                                      Tel:     0049 8153 9288-0
> Argelsrieder Feld 13                            Fax:     0049 8153 9288-11
> 82234 Wessling                                  E-Mail:  intec at simpack.de
> Germany                                         URL:
http://www.simpack.com
>
> ____________
> Virus checked by G DATA AntiVirus
> Version: AVB 19.313 from 28.04.2009
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.cmake.org/pipermail/cmake/attachments/20090429/e04b4c4f/attachment-0001.htm>


More information about the CMake mailing list