* Need help with eshell hack
@ 2007-12-20 21:43 Mathias Dahl
2007-12-20 23:32 ` Mathias Dahl
0 siblings, 1 reply; 3+ messages in thread
From: Mathias Dahl @ 2007-12-20 21:43 UTC (permalink / raw)
To: help-gnu-emacs
Inspired by `eev' I wanted to write a command that executes the current
line as a command in eshell. This is what I have:
(defun my-eshell-execute-current-line ()
"Insert text of current line in eshell and execute."
(interactive)
(let ((command (buffer-substring
(save-excursion
(beginning-of-line)
(point))
(save-excursion
(end-of-line)
(point)))))
(save-excursion
(unless (get-buffer eshell-buffer-name)
(eshell))
(display-buffer eshell-buffer-name t)
(set-buffer eshell-buffer-name)
(end-of-buffer)
(eshell-kill-input)
(insert command)
(eshell-send-input))))
It almost works. The problem is that when output from the command
reaches the bottom of the visible part of the eshell window, the window
isn't scrolled down to show the output.
Any idea on how to achieve this?
/Mathias
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Need help with eshell hack
2007-12-20 21:43 Need help with eshell hack Mathias Dahl
@ 2007-12-20 23:32 ` Mathias Dahl
2008-02-28 7:45 ` Kevin Rodgers
0 siblings, 1 reply; 3+ messages in thread
From: Mathias Dahl @ 2007-12-20 23:32 UTC (permalink / raw)
To: help-gnu-emacs
Mathias Dahl <mathias.dahl@gmail.com> writes:
> It almost works. The problem is that when output from the command
> reaches the bottom of the visible part of the eshell window, the
> window isn't scrolled down to show the output.
I let go of the `save-excursion' + `set-buffer' approach, in other words
being a bad boy, and got this that seems to work for me:
(defun my-eshell-execute-current-line ()
"Insert text of current line in eshell and execute."
(interactive)
(let ((command (buffer-substring
(save-excursion
(beginning-of-line)
(point))
(save-excursion
(end-of-line)
(point)))))
(let ((buf (current-buffer)))
(unless (get-buffer eshell-buffer-name)
(eshell))
(display-buffer eshell-buffer-name t)
(switch-to-buffer-other-window eshell-buffer-name)
(end-of-buffer)
(eshell-kill-input)
(insert command)
(eshell-send-input)
(end-of-buffer)
(switch-to-buffer-other-window buf))))
It annoys be however that I could not get it working without using
switch-to-buffer... The docstring says to avoid use it.
Oh well,
/Mathias
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Need help with eshell hack
2007-12-20 23:32 ` Mathias Dahl
@ 2008-02-28 7:45 ` Kevin Rodgers
0 siblings, 0 replies; 3+ messages in thread
From: Kevin Rodgers @ 2008-02-28 7:45 UTC (permalink / raw)
To: help-gnu-emacs
Mathias Dahl wrote:
> Mathias Dahl <mathias.dahl@gmail.com> writes:
>
>> It almost works. The problem is that when output from the command
>> reaches the bottom of the visible part of the eshell window, the
>> window isn't scrolled down to show the output.
>
> I let go of the `save-excursion' + `set-buffer' approach, in other words
> being a bad boy, and got this that seems to work for me:
>
> (defun my-eshell-execute-current-line ()
> "Insert text of current line in eshell and execute."
> (interactive)
> (let ((command (buffer-substring
> (save-excursion
> (beginning-of-line)
> (point))
> (save-excursion
> (end-of-line)
> (point)))))
(buffer-substring (line-beginning-position) (line-end-position))
> (let ((buf (current-buffer)))
> (unless (get-buffer eshell-buffer-name)
> (eshell))
> (display-buffer eshell-buffer-name t)
> (switch-to-buffer-other-window eshell-buffer-name)
> (end-of-buffer)
> (eshell-kill-input)
> (insert command)
> (eshell-send-input)
> (end-of-buffer)
> (switch-to-buffer-other-window buf))))
>
> It annoys be however that I could not get it working without using
> switch-to-buffer... The docstring says to avoid use it.
(pop-to-buffer eshell-buffer-name)
--
Kevin Rodgers
Denver, Colorado, USA
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2008-02-28 7:45 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-12-20 21:43 Need help with eshell hack Mathias Dahl
2007-12-20 23:32 ` Mathias Dahl
2008-02-28 7:45 ` Kevin Rodgers
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).