3

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.

2
  • Why write your own compilation command? There is already compile. Commented May 2, 2010 at 4:00
  • I don't know much about emacs lisp (or emacs for that matter) hence I can't create a function that would bind C-c C-c to compile. I found this function on SO and it works pretty well. Commented May 2, 2010 at 5:53

2 Answers 2

2

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))
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you very much, this worked like a charm. I changed the number of lines to 5 instead of 20 though.
0

I asked very similar question before: 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)

2 Comments

hi, i added this to my .emacs file but the problem persists
@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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.