From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: jadamson@partners.org (Joel J. Adamson) Newsgroups: gmane.emacs.help Subject: Re: first emacs lisp script: hello world Date: Thu, 13 Dec 2007 09:19:06 -0500 Organization: I need to put my ORGANIZATION here. Message-ID: <87y7byu17p.fsf@W0053328.mgh.harvard.edu> References: <7A8AFE3F49003F46B77954A8E6A7E32C4F9325@atl2corpx2.corp.interland.net> <87zlwmp3cf.fsf@W0053328.mgh.harvard.edu> <87mysicxv5.fsf@W0053328.mgh.harvard.edu> <86tzmq1jjh.fsf@timbral.net> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1197556848 14057 80.91.229.12 (13 Dec 2007 14:40:48 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 13 Dec 2007 14:40:48 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Thu Dec 13 15:40:58 2007 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1J2pF3-0005no-MJ for geh-help-gnu-emacs@m.gmane.org; Thu, 13 Dec 2007 15:40:50 +0100 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1J2pEi-0004P2-3Y for geh-help-gnu-emacs@m.gmane.org; Thu, 13 Dec 2007 09:40:28 -0500 Original-Path: shelby.stanford.edu!headwall.stanford.edu!newsfeed.news2me.com!news.glorb.com!newspeer1.asbnva01.us.to.verio.net!news.harvard.edu!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 90 Original-NNTP-Posting-Host: w0053328.mgh.harvard.edu Original-X-Trace: plato.harvard.edu 1197555546 19957 132.183.29.121 (13 Dec 2007 14:19:06 GMT) Original-X-Complaints-To: news@plato.harvard.edu Original-NNTP-Posting-Date: Thu, 13 Dec 2007 14:19:06 +0000 (UTC) Cancel-Lock: sha1:jjd0FldP73TBPrt4cb9F+1M41mw= Original-Xref: shelby.stanford.edu gnu.emacs.help:154640 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:50068 Archived-At: thorne writes: > jadamson@partners.org (Joel J. Adamson) writes: > >> Eric Hanchrow 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