3

Is there a way to get to the top of a buffer that is not necessarily active?

What I want to do is run a shell command on the word at point and then show the top of the output in the *Async Shell Command* buffer (if the output is longer than the screen).

What I have now is:

(evil-leader/set-key "l"
  (lambda ()
    (interactive)
    (async-shell-command
     (concat "parse " (thing-at-point 'word 'no-properties)))))

1 Answer 1

2

I think you don't want to use async-shell-command but start-process instead. That will let you decide when and how you display the output.

E.g. something like (guaranteed 100% untested):

(defun my-parse-command ()
  (interactive)
  (let* ((buf (get-buffer-create "*my-output-buffer*"))
         (proc (start-process
                "my-parse-proc" buf
                "parse" (thing-at-point 'word 'no-properties))))
    (set-process-sentinel
     proc
     (lambda (proc _state)
       (with-current-buffer (process-buffer proc)
         (save-excursion
           (goto-char (point-min))
           (if (>= (line-beginning-position 2) (point-max))
               ;; A single line of output, show in echo area
               (message "%s" (buffer-substring))
             (let ((win (display-buffer (current-buffer))))
               (when win
                 (fit-window-to-buffer win))))))))))

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.