tags:

views:

126

answers:

2

Hi ,

i have the following in my .emacs file(thanks to SOer nikwin), which evaluates the current buffer content and displays the output in another buffer.

 (defun shell-compile ()
  (interactive)
(save-buffer)
   (shell-command (concat "python " (buffer-file-name))))

 (add-hook 'python-mode-hook
           (lambda () (local-set-key (kbd "\C-c\C-c") 'shell-compile)))

The problem is that the output window takes half the emacs screen. Is there any way to set the output windows's height to something smaller. I googled for 30mins or so and could not find anything that worked. Thanks in advance.

A: 

I asked very similar question before: http://stackoverflow.com/questions/2205121/emacs-programmatically-change-window-size

this is what I used to have (before using ecb)

(defun collapse-compilation-window (buffer)
  "Shrink the window if the process finished successfully."
  (let ((compilation-window-height 5))
    (compilation-set-window-height (get-buffer-window buffer 0))))

(add-hook 'compilation-finish-functions
          (lambda (buf str)
            (if (string-match "exited abnormally" str)
;               (next-error)
              ;;no errors, make the compilation window go away in a few seconds
              ;(run-at-time "2 sec" nil 'delete-windows-on (get-buffer-create "*compilation*"))
              (collapse-compilation-window buf)
              (message "No Compilation Errors!")
              )
            ))

;(add-hook 'compilation-finish-functions 'my-compilation-finish-function)
aaa
hi, i added this to my .emacs file but the problem persists
jimbo
@jim my code snippet uses compilation buffer, rather than shell buffer. is not going to work as is, you can either try using compilation buffer or find out if there is equivalent finish-functions hook for the shell buffer
aaa
A: 

This expands the source code buffer by 20 lines whenever its height is less than or equal to half the frame's height. Pretty crude, but it may serve your purpose.

(defun shell-compile ()
  (interactive)
  (save-buffer)
  (shell-command (concat "python " (buffer-file-name)))
  (if (<= (* 2 (window-height)) (frame-height))
      (enlarge-window 20)
    nil))
unutbu
Thank you very much, this worked like a charm. I changed the number of lines to 5 instead of 20 though.
jimbo