From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: pjb@informatimago.com (Pascal J. Bourguignon) Newsgroups: gmane.emacs.help Subject: Re: Inserting output from a program into a buffer Date: Mon, 22 Feb 2010 10:41:07 +0100 Organization: Informatimago Message-ID: <87zl316218.fsf@galatea.lan.informatimago.com> References: <87zl324774.fsf@lion.rapttech.com.au> <87k4u66nhh.fsf@galatea.lan.informatimago.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: dough.gmane.org 1266840086 16369 80.91.229.12 (22 Feb 2010 12:01:26 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Mon, 22 Feb 2010 12:01:26 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Mon Feb 22 13:01:22 2010 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.69) (envelope-from ) id 1NjVjK-0002Jk-Ig for geh-help-gnu-emacs@m.gmane.org; Mon, 22 Feb 2010 11:41:35 +0100 Original-Received: from localhost ([127.0.0.1]:43187 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NjVjK-0007vL-2E for geh-help-gnu-emacs@m.gmane.org; Mon, 22 Feb 2010 05:41:34 -0500 Original-Path: news.stanford.edu!usenet.stanford.edu!news.tele.dk!news.tele.dk!small.news.tele.dk!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 70 Original-X-Trace: individual.net hnVh6CJ59qW0XBhqZBL5mgMkolF+KFolPjNQ1aRQFvbFWvVfqm Cancel-Lock: sha1:MGE5OGNhOGNkNjE0YWQxNTA1YWY0NGQwNmMxNmIzN2ZhNzlkNjkyMg== sha1:87wzGAkBL4lBkIPYkJFrYeZrjTs= Face: iVBORw0KGgoAAAANSUhEUgAAADAAAAAwAQMAAABtzGvEAAAABlBMVEUAAAD///+l2Z/dAAAA oElEQVR4nK3OsRHCMAwF0O8YQufUNIQRGIAja9CxSA55AxZgFO4coMgYrEDDQZWPIlNAjwq9 033pbOBPtbXuB6PKNBn5gZkhGa86Z4x2wE67O+06WxGD/HCOGR0deY3f9Ijwwt7rNGNf6Oac l/GuZTF1wFGKiYYHKSFAkjIo1b6sCYS1sVmFhhhahKQssRjRT90ITWUk6vvK3RsPGs+M1RuR mV+hO/VvFAAAAABJRU5ErkJggg== X-Accept-Language: fr, es, en X-Disabled: X-No-Archive: no User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (darwin) Original-Xref: news.stanford.edu gnu.emacs.help:176965 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:72011 Archived-At: Tim Johnson writes: > On 2010-02-22, Pascal J. Bourguignon wrote: > <..> >> You could get a string without attribute using the function >> buffer-substring-no-properties instead of buffer-substring. > Oh! Deja vu here... I believe that what I really need is > buffer-substring- to copy the region directly to a > variable. In general, functions don't modify variables. This would be a bad case of side effect. In emacs lisp it would be somewhat possible, since all the variables are dynamic variables. (In Scheme or Common Lisp it wouldn't even be possible for lexical variables!). However, even with dynamic variables, you cannot modify the variables if they are rebound in an inner dynamic scope. (defun f (x) (let ((var 42)) (list var (progn (set-var x) var)))) (defun set-var (x) (setq var x)) (defvar var 0) (set-var 33) var ; --> 33 ; seems to work. (f 22) ; --> (42 22) ; seems to have worked. var ; --> 33 ; but it really didn't worked. Well, really, it worked as it should but not as you would have wanted. (Notice that this effect is a design bug in LISP that was detected in 1960 and corrected in the following years by the introduction of lexical variables. emacs lisp is somewhat retrograde (or at least conservator) on this point). Anyways, it is a bad idea to try to modify variables from called functions. What you really need is to BIND the RESULT of buffer-string and other functions TO a variable. This is done with LET: (let ((string (buffer-substring (point-min) (+ 10 (point-min))))) (string= "Newsgroups" string)) --> t Or, in the improbable case you need to keep a value across functions, you may store it in a global variables (but global variables should be avoided as side effects in functions trying to modify them). (defvar *my-text* "") (setf *my-text* (buffer-substring (point-min) (+ 10 (point-min)))) *my-text* ; --> #("Newsgroups" 0 10 (fontified t face message-header-name)) Notice that while there's no lexical variables to protect against, I still think that we should use the *x* convention in emacs lisp for global variables, so that they're not accidentally shadowed by normal variables (lexical wanabees) such as the poor var above. But who I am to say such things, I'm not RMS... -- __Pascal Bourguignon__