From mboxrd@z Thu Jan 1 00:00:00 1970 From: pinard@iro.umontreal.ca (=?utf-8?Q?Fran=C3=A7ois?= Pinard) Subject: Re: [Orgmode] Automatic screenshot insertion Date: Tue, 10 Jan 2012 09:53:49 -0500 Message-ID: <87y5tf622q.fsf@iro.umontreal.ca> References: <4CE55F66.80802@gmail.com> <87vd3hmebo.wl%dmaus@ictsoc.de> <20110329144327.GE2902@x201> <87ehveyck1.fsf@iro.umontreal.ca> <87fwfoohn6.fsf@ucl.ac.uk> <87obucaanw.fsf@iro.umontreal.ca> <87wr90c4u0.fsf@ucl.ac.uk> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Return-path: Received: from eggs.gnu.org ([140.186.70.92]:56389) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Rkd5L-0007Kf-Hf for emacs-orgmode@gnu.org; Tue, 10 Jan 2012 09:54:04 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Rkd5D-0003yc-8O for emacs-orgmode@gnu.org; Tue, 10 Jan 2012 09:53:59 -0500 Received: from 206-248-137-202.dsl.teksavvy.com ([206.248.137.202]:64932 helo=mercure.epsilon-ti.ca) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Rkd5D-0003yV-22 for emacs-orgmode@gnu.org; Tue, 10 Jan 2012 09:53:51 -0500 In-Reply-To: <87wr90c4u0.fsf@ucl.ac.uk> (Eric S. Fraga's message of "Tue, 10 Jan 2012 08:57:43 +0000") List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: emacs-orgmode@gnu.org Eric S Fraga writes: Hi again, Eric. I'll be using your corrections on the code, thanks! > I had to add a call to expand-file-name for getting a file name which > worked on my system for some reason. (make-temp-name (expand-file-name (concat (file-name-as-directory name) (subst-char-in-string "." "-" (file-name-sans-extension (file-name-nondirectory (buffer-file-name))))))) ".png"))) Not a big deal, but I wonder if it should not rather be: (make-temp-name (concat (expand-file-name (file-name-as-directory name)) (subst-char-in-string "." "-" (file-name-sans-extension (file-name-nondirectory (buffer-file-name)))))) as there is nothing to expand in the base part of the file name? > I also re-arranged your second (unless ...) to an (if ...): (if (file-writable-p name) (progn (message "Taking screenshot into %s" name) (call-process "import" nil nil nil name) (message "Taking screenshot...done")) (error "Cannot create image file")) I kept it, but I might likely revert it back routinely to the earlier state, if I later happen to revisit that code. Just to show you how maniacal I may be, let me explain. I just do not like "(progn ...)", and make stunts to avoid it. I would rather write: (if (not (file-writable-p name)) (error "Cannot create image file") (message "Taking screenshot into %s" name) (call-process "import" nil nil nil name) (message "Taking screenshot...done")) Then, besides a few exceptions, I generally do not like else clauses after returning or other escaping statements, so the above becomes: (if (not (file-writable-p name)) (error "Cannot create image file")) (message "Taking screenshot into %s" name) (call-process "import" nil nil nil name) (message "Taking screenshot...done") Finally, I avoid "(not ...)" when this is easily done. I will always exchange the two branches of an "if" to get rid of one (unless it would imply re-introducing "(progn ..."), as progn is uglier than not :-). Easier here, as "(if (not ...))" may be rewritten "(unless ...)". By the way, "(when ...)" is always nicer than a single-branched "if". Scheme is especially irritating. They said it is minimalist, and yet, they have many ways to write conditional code, forcing me to choose constantly. I will turn "(if ...)" into "(cond ...)" if a "(begin ...)" becomes necessary on either branch. And a "(cond ...)" back to an "(if ...)" if while simplifying a cond, I see it could written to an if without begin. And there is always this stretch towards tail recursion, and so many ways to reuse or not local variables as arguments, doing so. Irritating I say. And yet, I love this language. Maniacal I am, really! Fran=C3=A7ois P.S. If you happen to grok French, you might have fun reading me (or making fun of me reading...): http://icule.blogspot.com/1997/02/dieu-la-douleur-et-l.html