From: Marcin Borkowski <mbork@mbork.pl>
To: Emanuel Berg <embe8573@student.uu.se>
Cc: help-gnu-emacs@gnu.org
Subject: Re: How to test if the current line contains only white-spache?
Date: Fri, 20 Nov 2015 07:14:19 +0100 [thread overview]
Message-ID: <87ziy9kxj8.fsf@mbork.pl> (raw)
In-Reply-To: <87ziy9k0cl.fsf@debian.uxu>
On 2015-11-20, at 00:58, Emanuel Berg <embe8573@student.uu.se> wrote:
> Marcin Borkowski <mbork@mbork.pl> writes:
>
>> On 2015-11-19, at 14:54, Rolf Ade
>> <rolf@pointsman.de>
>> wrote:
>>
>>> Yes, this is, what my instinct also telling me.
>>> But this instinct was trained by other programming
>>> languages and environments. I'm aware, that it may
>>> be not applicable to emacs lisp / emacs.
>>
>> And you're right: it's not.
>>
>>> Discussing programming concepts at such 'meta level'
>>> is difficult. But maybe some may express their
>>> thinking about this. Is this 'moving point around'
>>> in emacs lisp programming code the "right thing" to
>>> do [...]
>>
>> Yes it is.
>
> I don't think you can be categorical about it.
Of course I can. Though maybe I shouldn't. ;-)
But I don't say that this is a general rule, always applicable. Just
that it is a fine pattern in Elisp coding.
> `save-excursion' and `save-window-excursion' are there
> because they are useful. But just because they are
> useful doesn't mean they should always be used.
>
> As for "side-effects" that is the phantom menace the
> Haskell buffs came up with, when actually side effects
> are the reason we use computers.
>
> Rather, in this case it is clear which is preferable
> of
>
> (save-excursion (beginning-of-line) (point))
>
> and
>
> (line-beginning-position)
>
> The code is easier and faster to write, read,
> and understand.
Is it really clear? I'm not sure.
Besides, I've just checked the /implementation/ of
`line-beginning-position', and I have some bad news for you. I'm not
fluent in C, nut AFAICT, it's even uglier than the Elisp variant: there
is no `save-excursion', just a temporary variable for the original
position of point (which is how `save-excursion' probably has to work
anyway).
So, how is the C `line-beginning-position' better than
(defun elisp-line-beginning-position ()
(save-excursion (beginning-of-line) (point)))?
(apart from being less general)? It is just /faster/, but not more
/elegant/ or /pure/.
> This is even more true when the example isn't as basic
> as that, but when everything appears in nested forms
> and loops and what have you. If you rely on moving
> point around, this will demand of you to be a better
> programmer than you would have to be, less it will get
> out of hands pretty quickly.
Aren't /abstractions/ (like functions and/or macros) there to help me
with that?
> That is one aspect. The other aspect is that often
> moving point to the correct place to extract some data
> seems straightforward in the lab. In the field all
> sorts of unexpected situations appear and suddenly
> point doesn't land where it should (or remotely so!).
> Now the code once again can quickly get out of hands
> if you try to compensate if `looking-at' something
> `forward-char' else - and so on: not good!
Could you give a concrete example where your technique is superior
because of that?
> Note that save-excursion isn't only used to get data
> but perhaps most often to seemingly reset the state
> after something is done so tho the user is aware it
> happened (because he struck the command) he won't be
> bothered with the buffer flicking by in the process.
Of course, many commands (like `mark-word', for instance), are
/supposed/ to do something without moving the point.
Best,
--
Marcin Borkowski
http://octd.wmi.amu.edu.pl/en/Marcin_Borkowski
Faculty of Mathematics and Computer Science
Adam Mickiewicz University
next prev parent reply other threads:[~2015-11-20 6:14 UTC|newest]
Thread overview: 40+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-11-14 16:11 How to test if the current line contains only white-spache? Rolf Ade
2015-11-14 18:42 ` Barry Margolin
2015-11-15 13:29 ` Marcin Borkowski
2015-11-16 21:15 ` Philipp Stephani
2015-11-25 13:58 ` looking-at-p slower than looking-at Nicolas Richard
2015-11-25 20:34 ` Marcin Borkowski
2015-11-25 21:28 ` Michael Heerdegen
2015-11-25 21:32 ` Marcin Borkowski
2015-11-26 13:37 ` Nicolas Richard
2015-11-25 22:39 ` Emanuel Berg
2015-11-26 13:58 ` Nicolas Richard
[not found] ` <mailman.675.1448463102.31583.help-gnu-emacs@gnu.org>
2015-11-25 15:48 ` Barry Margolin
2015-11-25 20:39 ` Marcin Borkowski
2015-11-15 19:18 ` How to test if the current line contains only white-spache? Rolf Ade
2015-11-17 0:26 ` Emanuel Berg
2015-11-17 20:38 ` Marcin Borkowski
[not found] ` <mailman.23.1447720376.31583.help-gnu-emacs@gnu.org>
2015-11-19 1:56 ` Rolf Ade
2015-11-19 2:05 ` Stefan Monnier
2015-11-19 2:18 ` Emanuel Berg
2015-11-19 2:23 ` Emanuel Berg
[not found] ` <mailman.202.1447899839.31583.help-gnu-emacs@gnu.org>
2015-11-19 13:54 ` Rolf Ade
2015-11-19 15:20 ` Marcin Borkowski
2015-11-19 23:58 ` Emanuel Berg
2015-11-20 6:14 ` Marcin Borkowski [this message]
2015-11-21 2:26 ` Emanuel Berg
[not found] ` <mailman.279.1447976946.31583.help-gnu-emacs@gnu.org>
2015-11-20 0:48 ` How to test if the current line contains only white-space? Rolf Ade
2015-11-21 2:02 ` Emanuel Berg
[not found] ` <mailman.375.1448070734.31583.help-gnu-emacs@gnu.org>
2015-11-21 2:28 ` Rolf Ade
2015-11-24 3:01 ` Emanuel Berg
2015-11-20 0:48 ` Rolf Ade
2015-11-26 17:51 ` How to test if the current line contains only white-spache? Alex Bennée
2015-11-26 23:59 ` predicates (was: Re: How to test if the current line contains only white-spache?) Emanuel Berg
[not found] ` <mailman.787.1448581762.31583.help-gnu-emacs@gnu.org>
2015-11-27 4:28 ` predicates Pascal J. Bourguignon
2015-11-27 19:52 ` predicates Emanuel Berg
2015-11-15 5:56 ` How to test if the current line contains only white-spache? Yuri Khan
2015-11-15 9:18 ` John Mastro
2015-11-25 14:04 ` Nicolas Richard
2015-11-25 20:36 ` Marcin Borkowski
2015-11-25 22:41 ` Emanuel Berg
[not found] ` <mailman.676.1448463105.31583.help-gnu-emacs@gnu.org>
2015-11-26 15:24 ` Rolf Ade
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
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87ziy9kxj8.fsf@mbork.pl \
--to=mbork@mbork.pl \
--cc=embe8573@student.uu.se \
--cc=help-gnu-emacs@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.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).