From: jadamson@partners.org (Joel J. Adamson)
To: help-gnu-emacs@gnu.org
Subject: Re: first emacs lisp script: hello world
Date: Thu, 13 Dec 2007 09:19:06 -0500 [thread overview]
Message-ID: <87y7byu17p.fsf@W0053328.mgh.harvard.edu> (raw)
In-Reply-To: 86tzmq1jjh.fsf@timbral.net
thorne <thorne@timbral.net> writes:
> jadamson@partners.org (Joel J. Adamson) writes:
>
>> Eric Hanchrow <offby1@blarg.net> writes:
>>
>>> #!/usr/bin/emacs --script
>>> (message "Hello Biscuit-lovers!")
>>>
>>> Waal, shoot, Jackson; ah dint know 'bout thet thar --script option.
>>
>> It's pretty sweet, and I got the impression that it's a fairly new
>> feature since there's very little about it on EmacsWiki. I've already
>> written a couple shell-scripts in it.
>
> That is cool. Goodbye bash, hello Emacs.
You can manipulate buffers in an Emacs script and save them using the
regular file-saving and file-writing commands.
> But i couldn't find anything about it in the Emacs info file (though i
> did not search high and low) now on EmacsWiki.org.
Yeah, I found nothing myself, other than one note saying that it was a
very new feature and few people have used it. So I decided to try it out.
Appendix C.2 "Initial Options"
|`--script FILE'
| Run Emacs in batch mode, like `--batch', and then read and execute
| the Lisp code in FILE.
|
| The normal use of this option is in executable script files that
| run Emacs. They can start with this text on the first line
|
| #!/usr/bin/emacs --script
|
| which will invoke Emacs with `--script' and supply the name of the
| script file as FILE. Emacs Lisp then treats `#!' as a comment
| delimiter.
> I'd like to know basic stuff, like: Is there a way to get a
> command-line argument to the script?--etc.
The first two arguments are "/usr/bin/emacs" and "--script", so I access
command line options with (nthcdr 3 (command-line-args)), but think you
could use (command-line-args-left) instead. For example, when I want a
list of files to load and edit:
(setq files (nthcdr 3 command-line-args))
(dolist (file files)
(catch 'no-file
;; is the filereadable?
(if (file-readable-p file)
;; then find the file
(find-file file) ...)))
I started this to replace sed, since I mostly do substitutions, I wrote
a regex-replace function to take an alist of regexes and their
respective replacements. This way I just have to type the alist,
instead of
s/.../.../Ig
a corresponding bunch of times:
(defun jedit-strip-regex (alist)
"Takes a list of regex-replacement string pairs;
processes entire buffer."
(interactive "sList: ")
;; for each cell in alist, define regex and replacement text
(dolist (regex-cell alist)
(let ((regex (car regex-cell))
(replacement (cadr regex-cell)))
;; go to beginning of buffer
(goto-char (point-min))
;; when you find the search string, replace it with replacement
;; text
(while (re-search-forward regex nil t)
(replace-match replacement nil nil)))))
I previously posted this on gnu.emacs.sources without the accompanying
script that uses it.
Joel
--
Joel J. Adamson
Biostatistician
Pediatric Psychopharmacology Research Unit
Massachusetts General Hospital
Boston, MA 02114
(617) 643-1432
(303) 880-3109
next prev parent reply other threads:[~2007-12-13 14:19 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-12-07 15:11 first emacs lisp script: hello world Stewart Haddock
2007-12-07 17:18 ` Lennart Borgman (gmail)
2007-12-07 17:29 ` Eric Hanchrow
2007-12-07 17:44 ` Peter Dyballa
[not found] ` <mailman.4724.1197050200.18990.help-gnu-emacs@gnu.org>
2007-12-07 22:06 ` Joel J. Adamson
2007-12-07 23:52 ` Eric Hanchrow
[not found] ` <mailman.4745.1197071540.18990.help-gnu-emacs@gnu.org>
2007-12-10 16:34 ` Joel J. Adamson
2007-12-10 18:39 ` thorne
2007-12-12 21:29 ` Sebastian Tennant
2007-12-13 14:19 ` Joel J. Adamson [this message]
2007-12-11 16:08 ` Exal de Jesus Garcia Carrillo
2007-12-11 18:05 ` Joel J. Adamson
[not found] <mailman.4714.1197046346.18990.help-gnu-emacs@gnu.org>
2007-12-07 18:04 ` Joel J. Adamson
2007-12-07 18:08 ` Xah Lee
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=87y7byu17p.fsf@W0053328.mgh.harvard.edu \
--to=jadamson@partners.org \
--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).