unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: pjb@informatimago.com (Pascal J. Bourguignon)
To: help-gnu-emacs@gnu.org
Subject: Re: Bash Script Editing Mode?
Date: Thu, 07 Aug 2008 23:20:08 +0200	[thread overview]
Message-ID: <87hc9w1q0n.fsf@hubble.informatimago.com> (raw)
In-Reply-To: 361d08d2-b456-49c9-a578-53d1aaaf0b0f@a8g2000prf.googlegroups.com

formido <formido@gmail.com> writes:

> There's a shell mode, but it has a prompt and doesn't help you
> incrementally create a shell script as efficiently as it could, unless
> I'm missing something. Is there any shell script mode that works more
> like the elisp, python, or erlang repls, where you can execute your
> choice of several lines at once and you can go back and edit and
> execute the lines in situ? If I write a bash function, editing and
> reloading the function is a painful process. I'm looking for something
> a little bit like the Mac's BBEdit shell worksheets (only better).


First, try to get your terminology straight.  You want a
shell-script-mode that be more like shell-mode, not a shell-mode
that's a different shell-script-mode.

That is, when you type M-x shell RET, you get a buffer that is in the
shell-mode, where you can edit a shell command, and when you type RET,
you get it executed.

On the other hand, when you type C-x C-f ~/bin/new-script RET M-x
shell-script-mode RET yo uget a buffer that is in the
shell-script-mode, where you can edit a shell script,  but indeed for
now, you cannot have them executed from here.


> I considered altering the usual shell mode, but it would take more
> than slight edits, so I'm hoping something's already out there. For
> example, one should be able to go back to a function, tweak it, and
> reload with a minimum of keyboard fuss.

Well, if you consider the shell mode, there's an easy way to get what
you want:  just edit your commands, one by one, and type RET to try
them.  When you're happy with the result, type: history RET and
copy-and-paste all the commands to a shell script buffer, add some
minor edits, including a #!/bin/bash on the first line, and voilà.


But really, I would rather start from the shell-script-mode.  What is
missing, it's the parsing for shell-script "sexprs".   That is, keys
such as C-M-f are still bound to forward-sexp that parses a lisp sexp
instead of a shell one.  (The problem of course is that it's much
harder to parse a shell expression).

Anyways, you could implement some minimal parser.  It'd need to know
about continuation lines, <<EOF ... EOF literal input, ( ... ), $(
... ), $(( ... )), { ... } with the syntax before for the function
declaration, and the syntax of the compound builtins such as if/fi,
case/esac, etc.

Once you have implemented a pair of functions forward-shell-expression
and backward-shell-expression, you can easily implement a function
such as eval-last-shell-expression:

(defun eval-last-shell-expression (point)
  (interactiev "P")
  (let ((start (progn (backward-shell-expression) (point)))
        (end   (progn (forward-shell-expression)  (point))))
    (comint-send-string (inferior-shell-proc)
                        (buffer-substring start end))
    (comint-send-string (inferior-shell-proc) "\n")))

There remains only to bind these commands to C-M-f, C-M-b and C-x C-e.




But if you're as lazy as me, perhaps the best option would be to use
scsh.  You get a shell, but it's really a scheme, and there is already
all you need to edit scheme scripts, and C-x C-e already works.

-- 
__Pascal Bourguignon__                     http://www.informatimago.com/

PUBLIC NOTICE AS REQUIRED BY LAW: Any use of this product, in any
manner whatsoever, will increase the amount of disorder in the
universe. Although no liability is implied herein, the consumer is
warned that this process will ultimately lead to the heat death of
the universe.


  parent reply	other threads:[~2008-08-07 21:20 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-08-07 20:21 Bash Script Editing Mode? formido
2008-08-07 20:49 ` Mike Treseler
2008-08-07 22:10   ` formido
2008-08-07 20:53 ` Lennart Borgman (gmail)
2008-08-07 21:06 ` Thierry Volpiatto
2008-08-07 21:20 ` Pascal J. Bourguignon [this message]
2008-08-07 21:59   ` formido
     [not found] ` <mailman.16033.1218143342.18990.help-gnu-emacs@gnu.org>
2008-08-07 22:01   ` formido
     [not found] ` <mailman.16028.1218142452.18990.help-gnu-emacs@gnu.org>
2008-08-07 22:03   ` formido

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87hc9w1q0n.fsf@hubble.informatimago.com \
    --to=pjb@informatimago.com \
    --cc=help-gnu-emacs@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).