I have very practically zero experience with elisp but after reading the intro to programming that comes with emacs and trying out things I was able to put together a function that will evaluate a shell command with a file buffer's content and append the result to another buffer.
The command is running wolframscript on some bits of source code but that is really immaterial to my problem, which is that I have been unable to make the output buffer redisplay in its window so that its end is in the middle. What happens is every time I execute the script, the output is correctly appended to the output buffer but the output buffer does not recenter.
Can anyone see what am I doing wrong (or not doing) and help me out here? I've tried for a couple days, incl. reading up on the window vs buffer point and how it works but I am clearly missing something. Below is my code:
(defun wolframscript-on-buffer-file () "Run a shell command on the current buffer's file and append output to a buffer." (interactive) (let* ((file-name (buffer-file-name))) (if (null file-name) (message "Current buffer is not visiting a file.") (let* ((file-buffer (current-buffer)) (command "/usr/local/bin/wolframscript -file") (output-buffer-name (concat "*" command "*")) (output-buffer (get-buffer-create output-buffer-name))) (with-current-buffer output-buffer ;; Make the buffer writable so we can append (setq buffer-read-only nil) ;; Move to the end of the buffer, and insert a header line. (goto-char (point-max)) (insert "\n--- New Command Output ---\n") (let ((process-environment (copy-sequence process-environment))) (setenv "EMACS_PWD" (file-name-directory file-name)) (call-process-shell-command (concat command " " (shell-quote-argument file-name)) nil (current-buffer) nil)) (goto-char (point-max)) ;; tried here first, not working: (setq buffer-read-only t) (pop-to-buffer (current-buffer)) ;; also tried (recenter -1), not working (recenter 0)) (pop-to-buffer file-buffer) (with-current-buffer output-buffer (setq buffer-read-only t))))))