From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: =?ISO-8859-15?Q?Andreas_R=F6hler?= Newsgroups: gmane.emacs.help Subject: Re: About a programming tip Date: Thu, 21 Feb 2013 08:00:37 +0100 Message-ID: <5125C615.9080502@easy-emacs.de> References: <20130221095112.1c8466f4687368f36805ea40@gmail.com> <87y5eixj4g.fsf@gmail.com> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-15; format=flowed Content-Transfer-Encoding: 7bit X-Trace: ger.gmane.org 1361430044 10309 80.91.229.3 (21 Feb 2013 07:00:44 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 21 Feb 2013 07:00:44 +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 Feb 21 08:01:07 2013 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1U8Q9Q-0007iB-UP for geh-help-gnu-emacs@m.gmane.org; Thu, 21 Feb 2013 08:01:05 +0100 Original-Received: from localhost ([::1]:39469 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U8Q95-00041K-72 for geh-help-gnu-emacs@m.gmane.org; Thu, 21 Feb 2013 02:00:43 -0500 Original-Received: from eggs.gnu.org ([208.118.235.92]:38623) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U8Q8y-0003zv-0R for help-gnu-emacs@gnu.org; Thu, 21 Feb 2013 02:00:39 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1U8Q8u-0005Dc-5J for help-gnu-emacs@gnu.org; Thu, 21 Feb 2013 02:00:35 -0500 Original-Received: from moutng.kundenserver.de ([212.227.126.171]:51535) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U8Q8t-0005AC-Qy for help-gnu-emacs@gnu.org; Thu, 21 Feb 2013 02:00:32 -0500 Original-Received: from [192.168.178.21] (brln-4db9d9ac.pool.mediaWays.net [77.185.217.172]) by mrelayeu.kundenserver.de (node=mrbap3) with ESMTP (Nemesis) id 0Lxftz-1Ux98134Sx-017GLn; Thu, 21 Feb 2013 08:00:23 +0100 User-Agent: Mozilla/5.0 (X11; Linux i686; rv:17.0) Gecko/20130105 Thunderbird/17.0.2 In-Reply-To: <87y5eixj4g.fsf@gmail.com> X-Provags-ID: V02:K0:Xi2IG+hGdLEZ01+dPpTDNUozE8ZvyNSqrssXrjaz3mW fldxjA/MJEtOy32bKT0Fq4pyblq4GVN2UpvjhFAauSWftlc4nE Id4jmwjMtOIri73Y9bNSshzZdi1Wfw39le/x03H07IMPGqMhQi e49lgTGBv2n++RopXwjaQT6a73tRIWt58l5mSicsKQFybs3rP0 diNcStTWH5sU5+sjempyeLYv+cCp1zy2xwwK/iAVuIDGpFAltL IrTPJ3zYxPNcH4mSWVyEkkyGUGlsUNJvUlqyl9oz+zSHgi1Mdv u9oIyL8eVkQeHAdqGo+S02HW12d7YDbR9rGl1usW/EESKop1Sr Z3U/GBXLskQujRA6pBtT7drulK24GGN1rY0oSVYM8 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x-2.6.x [generic] X-Received-From: 212.227.126.171 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:89209 Archived-At: Am 21.02.2013 07:42, schrieb Thierry Volpiatto: > Xue Fuqiao writes: > >> In (info "(elisp) Programming Tips"): >> >> * In `interactive', if you use a Lisp expression to produce a list >> of arguments, don't try to provide the "correct" default values for >> region or position arguments. >> [...] >> You do not need to take such precautions when you use interactive >> specs `d', `m' and `r', because they make special arrangements to >> recompute the argument values on repetition of the command. >> >> I'm confused with these two sentences. The first sentence says that >> "don't try to provide the 'correct' default values for region or >> position arguments", but the second sentence says that "you don't need >> to take such precautions when you use interactive specs `d', `m' and >> `r'". IIRC the specs `d', `m' and `r' are "region or position >> arguments". Where do I understand wrong, or is it a bug? Thanks. > > (defun foo-1 (beg end) > (interactive (list (read-number "Beg: " (region-beginning)) > (read-number "End: " (region-end)))) > (message "%S" (buffer-substring beg end))) > > (defun foo (beg end) > (interactive "r") > (message "%S" (buffer-substring beg end))) > > In other words you don't have to use foo-1, it is easier to use foo. > IMO these remarks are misleading indeed, as the form "r" will raise an error if no region exists. Quite often I need a command, which works on region if existing, but uses some default if not - for example at the range of the function at point than. For example if it should work at the whole buffer by default, find in convenient to write (defun foo (&optional beg end) " " (interactive "*") (let ((beg (cond (beg) ((region-active-p) (region-beginning)) (t (point-min)))) (end (cond (end (copy-marker end)) ((region-active-p) (copy-marker (region-end))) (t (copy-marker (point-max))))))