[ESS] XEmacs, UNIX, ESS

Martin Maechler maechler at stat.math.ethz.ch
Tue Nov 25 18:47:48 CET 2008


>>>>> "RD" == Ramon Diaz-Uriarte <rdiaz02 at gmail.com>
>>>>>     on Fri, 21 Nov 2008 10:56:25 +0100 writes:

    RD> Sorry to jump into the conversation, being a complete emacs lisp ignorant.
    RD> push-line-other-window is really neat (and I just added it to my
    RD> .emacs). However, if I have more than two windows, I find the behavior
    RD> disconcerting. A while ago, I found the following solution, which I
    RD> added to my .emacs. It sends the marked line (which can be in any
    RD> window) to a shell process, and shows the output (if there is anything
    RD> to be shown). What I do not like is that it will not use the shell
    RD> process window if I have one open already.



  ;; Take entire current line and execute it as a shell command:
  ;; from http://linux.hostweb.com/TopicMessages/comp.os.linux.misc/1859693/25/Default.aspx
   (defun my-execute-line ()
     "Execute the line the cursor is on in a subshell"
     (interactive)
     (beginning-of-line)
     (if (eobp) (error "End of buffer"))
     (require 'sh-script)
     (let ((beg (point)))
       (forward-line 1)
       (sh-execute-region beg (point))))
  ;;; RDU:
  ;;; I'd like this to work as in ESS, but I can't simply
  ;;; do a global-set-key because that would break ESS, the python-ess like, etc.
  ;;; But I don't want them local now, because I sometimes execute pieces
  ;;; of shell code that are in arbitrary files (R, C, python, etc).
  (global-set-key "\C-cy" 'my-execute-line)
  (global-set-key "\C-cr" 'sh-execute-region)


> HTH,

not in the same way as the macro-using-solutions.

I had the same idea as you and wrote almost the same code as
you, but then I realized that

sh-execute-region  does *NOT* use the runing  *shell*
but rather forks a sub-shell which only lives for the execution
time.
This very different to what the OP  (and I) wanted.

But I agree that it would much nicer to have real elisp
functions that checked for existence *shell* used it where
possible, or started it otherwise, etc etc.

I append some unfinished code,
for anyone to take and improve.

However, *the real* solution would most probably use  comint-*
functions and variables the same way that the  ess-eval-*
functions do.

Martin

;; To: "Charles C. Berry" <cberry at tajo.ucsd.edu>
;; Cc: respostas17 at gmail.com,
;;     ess-help at stat.math.ethz.ch
;; Subject: Re: [ESS] XEmacs, UNIX, ESS
;; Reply-To: Martin Maechler <maechler at stat.math.ethz.ch>
;; --text follows this line--
;; >>>>> "ChuckB" == Charles C Berry <cberry at tajo.ucsd.edu>
;; >>>>>     on Wed, 19 Nov 2008 08:58:18 -0800 writes:

;;     ChuckB> On Wed, 19 Nov 2008, Luis F wrote:
;;     >> Dear Douglas, Richard, Mailing List:
;;     >>
;;     >> Thanks for such a quick reply. Douglas is absolutely
;;     >> right. I was precisely trying to write an email
;;     >> clarifying my unprecise mail. Sorry about that.
;;     >>
;;     >> Douglas Bates wrote:
;;     >>> On Wed, Nov 19, 2008 at 8:12 AM, Richard M. Heiberger
;;     >>> <rmh at temple.edu> wrote:
;;     >>>
;;     >>> > Use ESS.  The behavior is identical on Windows and
;;     >>> Unix.
;;     >>> >
;;     >>>
;;     >>> I believe Luis is asking a different question, Richard.
;;     >>> He wants to have separate shell and shell-script windows
;;     >>> in which he can send lines from the shell script window
;;     >>> to be executed in the shell window.  That is, he wants
;;     >>> to emulate some of the features provided by ESS for R,
;;     >>> S-PLUS (which apparently now has become S+) and SAS
;;     >>> source files in shell scripts.


;;     ChuckB> You can use shell-script-mode to edit the script and
;;     ChuckB> add his macro:

(fset 'push-line-other-window
      "\C-@\C-e\M-w\C-n\C-a\C-xo\M->\C-y\C-m\C-xo")
(global-set-key "\C-xp" 'push-line-other-window )

;;; MM's version: goto beginning of current line first
(fset 'push-line-other-window
      "\C-a\C-@\C-e\M-w\C-n\C-a\C-xo\M->\C-y\C-m\C-xo")

(fset 'push-region-other-window
      "\M-w\C-xo\M->\C-y\C-m\C-xo")
(global-set-key "\C-xw" 'push-region-other-window )


;; MM: Rather set this in shell-script-mode only !!


;;     ChuckB> to your .emacs (or wherever).

;; "cool";  thanks a lot, Chuck!

;; Indeed, I've also at times wanted to develop (ba)sh scripts as
;; easily as R's.

;; But why 'C-x p' rather than the same key-combination you use for R,
;; i.e  C-c C-n  or  C-c C-j ?

;; And, since we are here,  why don't you want the equivalent of
;; C-c C-r  (...eval-region) as well ?

;; Ok. Typing the standard  'C-h m' (describe-mode) in a
;; shell-script-mode buffer, and then looking at the key bindings
;; ("definitions") that are there and documented,
;; two things are to be noticed:

;; 1) C-c C-r is already assigned to "repeat loop"   .... too bad...

;; 2) C-M-x  is "Have optional header and region be executed in a subshell."

;;    wow, that's sounds interesting!

;; But alas, "in a subshell" is not what we want: We want the shell
;; running in the '*shell*' buffer.


(defun sh-eval-line-and-step ()
  "Evaluate the current line in the \\[shell] buffer, and step
   forward to the next line in the shell-script buffer."
  (interactive)
  (save-excursion
    (end-of-line)
    (let ((end (point))
    	  (n-win (length (window-list))))

      (beginning-of-line)
      (kill-new (filter-buffer-substring (point) end))
      ;; is part of (copy-region-as-kill (point) end)

      (if (= 1 n-win)
	  (split-window-vertically))

      (other-window 1)
      (shell); go to existing *shell* or start it
      (goto-char (point-max)); ~> end-of-buffer
      (yank)
      (comint-send-input); = [RET] aka [Enter]
      ));; end of save-excursion ==> back to original buffer

  (forward-line 1))




;;     ChuckB> With the shell-script-mode window open and the
;;     ChuckB> shell-mode window open, you can use C-X p to send a
;;     ChuckB> line from the former to the latter.

;;     ChuckB> My thanks to the orignator of this macro and
;;     ChuckB> apologies for forgetting his/her name. I think it
;;     ChuckB> was posted on S-news. I've used it for years when I
;;     ChuckB> want to move a line from one buffer to another.


;;     ChuckB> HTH,

;;     ChuckB> Chuck


;;     >>>
;;     >>>
;;     >>> > -----Original Message----- > From:
;;     >>> ess-help-bounces at stat.math.ethz.ch >
;;     >>> [mailto:ess-help-bounces at stat.math.ethz.ch] On Behalf Of
;;     >>> Luis F > Sent: Wednesday, November 19, 2008 09:02 > To:
;;     >>> ess-help at stat.math.ethz.ch > Subject: [ESS] XEmacs,
;;     >>> UNIX, ESS
;;     >>> >
;;     >>> > Dear Mailing List,
;;     >>> >
;;     >>> > I am a biologist, very used to program in R using
;;     >>> XEmacs and ESS. I have > to do some little things in
;;     >>> UNIX now. I would love to have something > similar to
;;     >>> what I'm used to with ESS.
;;     >>> >
;;     >>> > Mainly: > 1) a shell script on my top window > 2) a
;;     >>> shell on my bottom window > 3) send commands from the
;;     >>> script (one line at the time, similar to C-c > C-n; a
;;     >>> region - C-C C-r; the whole file C-c C-l)
;;     >>> >
;;     >>> > I could already do 1) and 2) (alt-x shell) (major
;;     >>> achievements!) and I > can copy-paste, go from one
;;     >>> window do the next (C-x o) and that is > already a great
;;     >>> improvment.
;;     >>> >
;;     >>> > But I can't do 3). Any suggestions?
;;     >>> >
;;     >>> > I realize this might be a question outside of the
;;     >>> strict scope of this > list (and I appologize if anyone
;;     >>> feels this is spam); I decided to post > it here,
;;     >>> because after searching for a while in the web, i felt
;;     >>> this > specific request would be more understood by
;;     >>> people in here.
;;     >>> >
;;     >>> > Thank you all for your work, > Tiago
;;     >>> >
;;     >>> > ______________________________________________ >

;;     ChuckB> Charles C. Berry                            (858) 534-2098
;;     ChuckB>                                              Dept of
;;     ChuckB> Family/Preventive Medicine E
;;     ChuckB> mailto:cberry at tajo.ucsd.edu UC San Diego
;;     ChuckB> http://famprevmed.ucsd.edu/faculty/cberry/ La Jolla,
;;     ChuckB> San Diego 92093-0901




More information about the ESS-help mailing list