Reputation: 9850
I'm trying to write a function that compiles some code, and if the compilation succeeds, it spawns the process and opens its output in a new window. The compilation bit works fine, but there's something weird going on with the second part. I wrote some code that looks like this:
(defun test-function ()
(with-current-buffer (get-buffer-create "*output*")
(erase-buffer)
(start-process "echo" (current-buffer) "echo" "hi")
(pop-to-buffer (current-buffer))))
This code almost works, but when it runs, the top of the screen seems to sit right below the actual output of the program. So, once echo
quits, the screen looks like
Process echo finished
And scrolling up one line gives (the expected)
blah Process echo finished
Is there a way to get it to start at the actual top of the buffer? I've tried things like scroll-up
and goto-char
before and after starting the process, but they don't seem to affect anything. From some other sources, it seems like I could attach a sentinel to the process and have it scroll up when there's output, but that seems like overkill just to scroll up at the beginning.
Upvotes: 4
Views: 225
Reputation: 67
Fixing it with a process sentinel:
(defun recenter-temp-buffer (process event)
(pop-to-buffer (process-buffer process)) (recenter-top-bottom))
(with-output-to-temp-buffer "test-buffer"
(set-process-sentinel
(start-process "test-process" "test-buffer" "echo" "hello")
'recenter-temp-buffer))
Note that the sentinel will call (recenter-top-bottom)
on every status change, which may not be what you want.
Upvotes: 0
Reputation: 2866
A bit of a hack, but for me this works:
(insert "\n")
(start-process ...
Upvotes: 1
Reputation: 13447
It looks like there is an \n
before Process
built into process.c
. Perhaps someone can suggest for you how to modify this after Emacs has already been built -- if not, a custom build seems like an extreme solution.
Of course, you could use elisp code to go up and delete the hard return after the fact.
Searching 5342 files for "\nprocess"
/Users/HOME/Desktop/emacs-trunk/src/process.c:
6405 tem = BVAR (current_buffer, read_only);
6406 bset_read_only (current_buffer, Qnil);
6407: insert_string ("\nProcess ");
6408 { /* FIXME: temporary kludge. */
6409 Lisp_Object tem2 = p->name; Finsert (1, &tem2); }
/Users/HOME/Desktop/emacs-trunk/lisp/man.el:
1304 (substring msg 0 eos) msg))))
1305 (goto-char (point-max))
1306: (insert (format "\nprocess %s" msg))))
1307 ))
1308 (if delete-buff
/Users/HOME/Desktop/emacs-trunk/lisp/progmodes/sql.el:
3944 (if (and (eq (current-buffer) sql-buffer)
3945 (not buffer-read-only))
3946: (insert (format "\nProcess %s %s\n" process event))
3947 (message "Process %s %s" process event)))
3948
/Users/HOME/Desktop/emacs-trunk/lisp/shell.el:
641 (when (buffer-live-p buf)
642 (with-current-buffer buf
643: (insert (format "\nProcess %s %s\n" process event))))))
644
645 ;;;###autoload
4 matches across 4 files
Upvotes: 0