From: pinard@iro.umontreal.ca (François Pinard)
To: emacs-orgmode@gnu.org
Subject: Re: [Orgmode] Automatic screenshot insertion
Date: Tue, 10 Jan 2012 09:53:49 -0500 [thread overview]
Message-ID: <87y5tf622q.fsf@iro.umontreal.ca> (raw)
In-Reply-To: <87wr90c4u0.fsf@ucl.ac.uk> (Eric S. Fraga's message of "Tue, 10 Jan 2012 08:57:43 +0000")
Eric S Fraga <e.fraga@ucl.ac.uk> 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çois
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
next prev parent reply other threads:[~2012-01-10 14:54 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-11-18 17:16 Automatic screenshot insertion Jonathan BISSON
2010-11-18 17:50 ` Sébastien Vauban
2010-11-28 19:35 ` David Maus
2011-03-29 14:43 ` [Orgmode] " Russell Adams
2011-06-06 18:59 ` David Maus
2012-01-05 4:54 ` François Pinard
2012-01-09 18:27 ` Eric S Fraga
2012-01-09 20:22 ` François Pinard
2012-01-10 8:57 ` Eric S Fraga
2012-01-10 14:53 ` François Pinard [this message]
2012-01-10 16:08 ` Eric S Fraga
2012-01-10 19:27 ` François Pinard
2012-01-10 19:46 ` Skip Collins
2012-01-11 5:50 ` Jambunathan K
2012-01-12 5:26 ` Skip Collins
2012-01-12 6:26 ` Thomas S. Dye
2012-01-14 21:35 ` François Pinard
2012-01-15 6:37 ` Marcelo de Moraes Serpa
2012-01-15 12:10 ` Russell Adams
2012-01-15 19:31 ` Marcelo de Moraes Serpa
2012-01-15 21:45 ` Russell Adams
2012-01-10 20:26 ` Eric S Fraga
2011-02-03 13:33 ` Bastien
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87y5tf622q.fsf@iro.umontreal.ca \
--to=pinard@iro.umontreal.ca \
--cc=emacs-orgmode@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.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.