Splitting a Window in Emacs Lisp Functions

I would like to be able to run a shell command on the current file that I am editing and have the output displayed in the shell command output window. I was able to identify which is shown below.

(defun cpp-check ()
  "Run cpp-check on current file the buffer is visiting."
  (shell-command
   (concat "/home/sburke/downloads/cppcheck-1.31/cppcheck "
       (buffer-file-name))))

      

The only problem is that the output window is not brought to the front in any way. I would like the window to be split and the output window to appear. Also, I am on the right track here defining a function to be placed in my .emacs file, or is there a better way?

Any help would be greatly appreciated. Thanks.

+1


source to share


4 answers


Here's what I came up with. Thanks for answers. I have defined a function that will go ahead and run cpp-check. I wanted this to be associated with a key in c mode, so I add it as a hook. I ran into the difference between normal functions and functions that can be bound to layouts, so I had to make this function interactive. This article helped explain this. So now, when the shortcut is clicked, the results appear in another window, but the cursor remains in the original buffer, which is what I want. The only problem is that the output is also displayed in the minibuffer, which is not exactly what I want. Any thoughts on fixing this little thing?



(defun cpp-check ()
  (interactive)
  "Run cpp-check on current file the buffer is visiting."
  (shell-command
   (concat "/home/sburke/downloads/cppcheck-1.31/cppcheck "
       (buffer-file-name)))
  (display-buffer "*Shell Command Output*"))

(add-hook 'c-mode-common-hook
           (lambda ()
         (define-key c-mode-base-map
               "\C-x\p" 'cpp-check)))

      

+2


source


Take a look at the documentation for 'shell-command

, this worked for me:

(defun cpp-check ()
  "Run cpp-check on current file the buffer is visiting."
  (shell-command
   (concat "/home/sburke/downloads/cppcheck-1.31/cppcheck "
       (buffer-file-name))
   "cpp-check"))

      



Creates a new buffer named "cpp-check" and places the results there. The current frame is split into, and the "cpp-check" buffer is placed in another window.

+4


source


See the `pop-to-buffer 'function. I think.

You should be able to give it a buffer name for pop - just specify the Shell Command in the buffer.

+3


source


splitting a window (split-window-vertically). It takes an optional argument of the size (top if positive, bottom if negative) of the window.

Then you need to conclude that the shell's output buffer has been brought to the fore by the switch-to-buffer or by the switch-to-buffer-to-another-window.

Remember that when you insert a window (frame) into emacs, you get two "windows" because the naming gets confused on the same day, which is too late to deal with it now ...

+1


source







All Articles