* forward-paragraph return value @ 2010-08-23 18:25 Andreas Röhler 2010-08-23 20:59 ` Andreas Schwab 0 siblings, 1 reply; 9+ messages in thread From: Andreas Röhler @ 2010-08-23 18:25 UTC (permalink / raw To: Emacs developers Hi, `forward-paragraph' presently returns "0" if the number of steps given by ARG is completed. It's code ends with: ;; Return the number of steps that could not be done. arg)) IMHO buffer-position reached is a more useful return value. Function may return point only when successfully, nil otherwise. Thanks all Andreas -- https://code.launchpad.net/~a-roehler/python-mode https://code.launchpad.net/s-x-emacs-werkstatt/ ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: forward-paragraph return value 2010-08-23 18:25 forward-paragraph return value Andreas Röhler @ 2010-08-23 20:59 ` Andreas Schwab 2010-08-24 5:43 ` Andreas Röhler 0 siblings, 1 reply; 9+ messages in thread From: Andreas Schwab @ 2010-08-23 20:59 UTC (permalink / raw To: Andreas Röhler; +Cc: Emacs developers Andreas Röhler <andreas.roehler@online.de> writes: > `forward-paragraph' presently returns "0" if the number of steps given by > ARG is completed. It's code ends with: > > ;; Return the number of steps that could not be done. > arg)) Which makes it similar to forward-line. > IMHO buffer-position reached is a more useful return value. Which you can get with (point). So what's the point? Andreas. -- Andreas Schwab, schwab@linux-m68k.org GPG Key fingerprint = 58CA 54C7 6D53 942B 1756 01D3 44D5 214B 8276 4ED5 "And now for something completely different." ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: forward-paragraph return value 2010-08-23 20:59 ` Andreas Schwab @ 2010-08-24 5:43 ` Andreas Röhler 2010-08-24 8:27 ` Stephen J. Turnbull 0 siblings, 1 reply; 9+ messages in thread From: Andreas Röhler @ 2010-08-24 5:43 UTC (permalink / raw To: Andreas Schwab; +Cc: Emacs developers Am 23.08.2010 22:59, schrieb Andreas Schwab: > Andreas Röhler<andreas.roehler@online.de> writes: > > >> `forward-paragraph' presently returns "0" if the number of steps given by >> ARG is completed. It's code ends with: >> >> ;; Return the number of steps that could not be done. >> arg)) >> > Which makes it similar to forward-line. > > >> IMHO buffer-position reached is a more useful return value. >> > Which you can get with (point). So what's the point? > > Andreas. > > Having a consistent design meeting expectations. For example a function designed to move point should return new position. Then people may write functions taking already the return value. Thats more nice than writing FORWARD (point). Presently return values of move functions are not regular. Some return nil or t, some positions IIRC, this one it's remaining loop variable. Well, would consider re-write efforts and not suggest that now for skip-char functions. In case of moves over paragraphs its easily done. Andreas -- https://code.launchpad.net/~a-roehler/python-mode https://code.launchpad.net/s-x-emacs-werkstatt/ ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: forward-paragraph return value 2010-08-24 5:43 ` Andreas Röhler @ 2010-08-24 8:27 ` Stephen J. Turnbull 2010-08-24 9:14 ` Andreas Röhler 0 siblings, 1 reply; 9+ messages in thread From: Stephen J. Turnbull @ 2010-08-24 8:27 UTC (permalink / raw To: Andreas Röhler; +Cc: Andreas Schwab, Emacs developers Andreas Röhler writes: > Then people may write functions taking already the return value. Sure. But will they? Show us examples of existing functions (preferably already in Emacs) that would benefit from this change. An easy example would be functions which look like ;; some code here (forward-paragraph count) (foo (point) other args) ;; more code But it's not clear to me that ;; some code here (foo (forward-paragraph count) other args) ;; more code is going to be more readable without seeing examples. Since point has a byte code, it's not particularly costly to use point. ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: forward-paragraph return value 2010-08-24 8:27 ` Stephen J. Turnbull @ 2010-08-24 9:14 ` Andreas Röhler 2010-08-24 11:30 ` Davis Herring 2010-08-24 12:06 ` Stephen J. Turnbull 0 siblings, 2 replies; 9+ messages in thread From: Andreas Röhler @ 2010-08-24 9:14 UTC (permalink / raw To: Stephen J. Turnbull; +Cc: Andreas Schwab, Emacs developers Am 24.08.2010 10:27, schrieb Stephen J. Turnbull: > Andreas Röhler writes: > > > Then people may write functions taking already the return value. > > Sure. But will they? Show us examples of existing functions > (preferably already in Emacs) that would benefit from this change. > Didn't I point to? If a look in forward-paragraph doesn't speak to you, maybe have a look into bounds-of-thing-at-point . Forms like (let (beg (progn (funcall (or (get thing 'beginning-op) (lambda () (forward-thing thing -1)))) (point)))) Thats bug-sourcing BTW, as it returns point in any case, even if move failed. Why not make implementation of return value from search-forward canonical instead, returning the position if succesful, nil otherwise. The gain will be for newly written code. For writers first, who must not learn function by function the return value. In the example above we could write (let (beg (funcall (or (get thing 'beginning-op) (lambda () (forward-thing thing -1)))))) Its clean and much more reliable, as beg will be nil, if nothing was found. > An easy example would be functions which look like > > ;; some code here > (forward-paragraph count) > (foo (point) other args) > ;; more code > > But it's not clear to me that > > ;; some code here > (foo (forward-paragraph count) other args) > ;; more code > > is going to be more readable without seeing examples. Since point has > a byte code, it's not particularly costly to use point. > > ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: forward-paragraph return value 2010-08-24 9:14 ` Andreas Röhler @ 2010-08-24 11:30 ` Davis Herring 2010-08-24 16:57 ` Andreas Röhler 2010-08-24 12:06 ` Stephen J. Turnbull 1 sibling, 1 reply; 9+ messages in thread From: Davis Herring @ 2010-08-24 11:30 UTC (permalink / raw To: Andreas Röhler; +Cc: Stephen J. Turnbull, Andreas Schwab, Emacs developers > Its clean and much more reliable, as beg will be nil, if nothing was > found. If (forward-paragraph 10) can only advance past 7 paragraphs, has it failed or not? And how is the caller to know that what they asked for was impossible if it merely returns (point-end) or so? Davis -- This product is sold by volume, not by mass. If it appears too dense or too sparse, it is because mass-energy conversion has occurred during shipping. ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: forward-paragraph return value 2010-08-24 11:30 ` Davis Herring @ 2010-08-24 16:57 ` Andreas Röhler 0 siblings, 0 replies; 9+ messages in thread From: Andreas Röhler @ 2010-08-24 16:57 UTC (permalink / raw To: herring; +Cc: Stephen J. Turnbull, Andreas Schwab, Emacs developers Am 24.08.2010 13:30, schrieb Davis Herring: >> Its clean and much more reliable, as beg will be nil, if nothing was >> found. >> > If (forward-paragraph 10) can only advance past 7 paragraphs, has it > failed or not? And how is the caller to know that what they asked for was > impossible if it merely returns (point-end) or so? > > Davis > > Example mentioned was search-forward. It sends all the info you need. ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: forward-paragraph return value 2010-08-24 9:14 ` Andreas Röhler 2010-08-24 11:30 ` Davis Herring @ 2010-08-24 12:06 ` Stephen J. Turnbull 2010-08-24 17:10 ` Andreas Röhler 1 sibling, 1 reply; 9+ messages in thread From: Stephen J. Turnbull @ 2010-08-24 12:06 UTC (permalink / raw To: Andreas Röhler; +Cc: Andreas Schwab, Emacs developers Andreas Röhler writes: > Am 24.08.2010 10:27, schrieb Stephen J. Turnbull: > > Andreas Röhler writes: > > > > > Then people may write functions taking already the return > > > value. > > Sure. But will they? Show us examples of existing functions > > (preferably already in Emacs) that would benefit from this > > change. > > > > Didn't I point to? > > If a look in forward-paragraph doesn't speak to you, Of course that doesn't speak to me; that's the function you propose to change. > maybe have a look into > > bounds-of-thing-at-point . `forward-paragraph' is a command. `bounds-of-thing-at-point' is not. There's a big difference. > Forms like > (let > (beg > (progn > (funcall > (or (get thing 'beginning-op) > (lambda () (forward-thing thing -1)))) > (point)))) I doubt that form appears anywhere in Emacs. The style is nauseating, not to mention that `progn' is a very unusual choice for a variable you are let-binding. ;-) Please give *real* examples, or if you're going to simplify real code to make your point, say that's what you're doing. And do it correctly, even for a fragment like this. > Thats bug-sourcing BTW, as it returns point in any case, even if > move failed. Why not make implementation of return value from > > search-forward > > canonical instead, returning the position if succesful, nil > otherwise. Er, because otherwise `search-forward' does not return nil, but rather signals an error? You need to specify additional arguments to get it to return nil. There's a reason for this interface, related to the fact that `search-forward' is a command, as is `forward-paragraph'. > The gain will be for newly written code. For writers first, who > must not learn function by function the return value. A common convention might be a good idea. It's a better idea for non-commands than it is for commands, though. > In the example above we could write > > (let > (beg > (funcall > (or (get thing 'beginning-op) > (lambda () (forward-thing thing -1)))))) > > Its clean and much more reliable, as beg will be nil, if nothing > was found. Maybe. But in fact, this is a (broken) copy of (part of) the implementation of `bounds-of-thing-at-point'. At least in XEmacs, that function has *much* bigger problems than the return value of forward-thing. Also, since the return value of `forward-thing' is undocumented (and probably rather unreliable), you could change that, or define an internal function for the use of functions defun'ed in thingatpt.el. The issue with forward-paragraph is quite different, because it is documented and it is a command. ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: forward-paragraph return value 2010-08-24 12:06 ` Stephen J. Turnbull @ 2010-08-24 17:10 ` Andreas Röhler 0 siblings, 0 replies; 9+ messages in thread From: Andreas Röhler @ 2010-08-24 17:10 UTC (permalink / raw To: emacs-devel; +Cc: Stephen J. Turnbull, Andreas Schwab Am 24.08.2010 14:06, schrieb Stephen J. Turnbull: > Andreas Röhler writes: > > Am 24.08.2010 10:27, schrieb Stephen J. Turnbull: > > > Andreas Röhler writes: > > > > > > > Then people may write functions taking already the return > > > > value. > > > Sure. But will they? Show us examples of existing functions > > > (preferably already in Emacs) that would benefit from this > > > change. > > > > > > > Didn't I point to? > > > > If a look in forward-paragraph doesn't speak to you, > > Of course that doesn't speak to me; that's the function you propose to > change. > > > maybe have a look into > > > > bounds-of-thing-at-point . > > `forward-paragraph' is a command. `bounds-of-thing-at-point' is not. > There's a big difference. > > > Forms like > > (let > > (beg > > (progn > > (funcall > > (or (get thing 'beginning-op) > > (lambda () (forward-thing thing -1)))) > > (point)))) > > I doubt that form appears anywhere in Emacs. The style is nauseating, > not to mention that `progn' is a very unusual choice for a variable > you are let-binding. ;-) Please give *real* examples, it is, just the var is called real-beg, which make things still more confusion and has been let aside here as an example was the concern (real-beg (progn (funcall (or (get thing 'beginning-op) (lambda () (forward-thing thing -1)))) (point)))) Also you may see ;; If that brings us all the way back to ORIG, ;; it worked. But END may not be the real end. ;; So find the real end that corresponds to BEG. (let ((real-end (progn (funcall (or (get thing 'end-op) (lambda () (forward-thing thing 1)))) (point)))) > or if you're > going to simplify real code to make your point, say that's what you're > doing. Please stop insinuations. > And do it correctly, even for a fragment like this. > > > Thats bug-sourcing BTW, as it returns point in any case, even if > > move failed. Why not make implementation of return value from > > > > search-forward > > > > canonical instead, returning the position if succesful, nil > > otherwise. > > Er, because otherwise `search-forward' does not return nil, but rather > signals an error? You need to specify additional arguments to get it > to return nil. There's a reason for this interface, related to the > fact that `search-forward' is a command, as is `forward-paragraph'. > > > The gain will be for newly written code. For writers first, who > > must not learn function by function the return value. > > A common convention might be a good idea. It's a better idea for > non-commands than it is for commands, though. > > > In the example above we could write > > > > (let > > (beg > > (funcall > > (or (get thing 'beginning-op) > > (lambda () (forward-thing thing -1)))))) > > > > Its clean and much more reliable, as beg will be nil, if nothing > > was found. > > Maybe. But in fact, this is a (broken) copy of (part of) the > implementation of `bounds-of-thing-at-point'. At least in XEmacs, > that function has *much* bigger problems than the return value of > forward-thing. Same in Emacs. But for the reasons just started to discuss. It's simply not written to the end, not thought through. Or it's author had to leave in the middle of his work. I wonder what happened, as it's a great set-out, a fine idea. For me one of the most interesting stuff in Emacs. Thanks BTW. Andreas > Also, since the return value of `forward-thing' is > undocumented (and probably rather unreliable), you could change that, > or define an internal function for the use of functions defun'ed in > thingatpt.el. > > The issue with forward-paragraph is quite different, because it is > documented and it is a command. > > > ^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2010-08-24 17:10 UTC | newest] Thread overview: 9+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2010-08-23 18:25 forward-paragraph return value Andreas Röhler 2010-08-23 20:59 ` Andreas Schwab 2010-08-24 5:43 ` Andreas Röhler 2010-08-24 8:27 ` Stephen J. Turnbull 2010-08-24 9:14 ` Andreas Röhler 2010-08-24 11:30 ` Davis Herring 2010-08-24 16:57 ` Andreas Röhler 2010-08-24 12:06 ` Stephen J. Turnbull 2010-08-24 17:10 ` Andreas Röhler
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.