* bug#24605: Subject: 25.1.50; form-at-point might fail for some THINGS
@ 2016-10-04 6:22 Tino Calancha
2016-10-05 1:15 ` npostavs
` (2 more replies)
0 siblings, 3 replies; 11+ messages in thread
From: Tino Calancha @ 2016-10-04 6:22 UTC (permalink / raw)
To: 24605; +Cc: Tino Calancha
[-- Attachment #1: Type: text/plain, Size: 2532 bytes --]
Because `thing-at-point' doesn't return always a string, as
`form-at-point' currently assumes. It might return a different
type depending on what you have in
(get thing 'thing-at-point)
emacs -Q:
(with-temp-buffer
(require 'thingatpt)
(insert "1")
(let ((res
(cond ((and (number-at-point)
(form-at-point 'number)) 0)
((and (number-at-point)
(not (form-at-point 'number))) -1)
((and (not (number-at-point))
(form-at-point 'number)) -2)
((and (not (number-at-point))
(not (form-at-point 'number))) -3))))
(pcase res
('0 (message "OK, both 'number-at-point and 'form-at-point successfull"))
(-1 (message "'number-at-point' works but (form-at-point 'number) fails"))
(-2 (message "(form-at-point 'number) works but 'number-at-point' fails"))
(-3 (message "Both 'number-at-point' and (form-at-point 'number) fails")))))
=> "’number-at-point’ works but (form-at-point ’number) fails"
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
From d587d00fc1379b8bd2511d5491c0c664669fef87 Mon Sep 17 00:00:00 2001
From: Tino Calancha <tino.calancha@gmail.com>
Date: Tue, 4 Oct 2016 14:48:36 +0900
Subject: [PATCH] form-at-point work for all kind of THINGS
* lisp/thingatpt.el (form-at-point):
Use thing-at-point--read-from-whole-string only if thing-at-point
returns a string (Bug#24605).
---
lisp/thingatpt.el | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/lisp/thingatpt.el b/lisp/thingatpt.el
index df5c52d..304df7b 100644
--- a/lisp/thingatpt.el
+++ b/lisp/thingatpt.el
@@ -586,9 +586,11 @@ 'read-from-whole-string
"This is an internal thingatpt function and should not be used.")
(defun form-at-point (&optional thing pred)
- (let ((sexp (ignore-errors
- (thing-at-point--read-from-whole-string
- (thing-at-point (or thing 'sexp))))))
+ (let* ((obj (thing-at-point (or thing 'sexp)))
+ (sexp (ignore-errors
+ (if (stringp obj)
+ (thing-at-point--read-from-whole-string obj)
+ obj))))
(if (or (not pred) (funcall pred sexp)) sexp)))
;;;###autoload
--
2.9.3
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
In GNU Emacs 25.1.50.1 (x86_64-pc-linux-gnu, GTK+ Version 3.22.0)
of 2016-10-04 built on calancha-pc
Repository revision: 74b4f13842f3119f98797ea76d9be42457b330e1
^ permalink raw reply related [flat|nested] 11+ messages in thread
* bug#24605: Subject: 25.1.50; form-at-point might fail for some THINGS
2016-10-04 6:22 bug#24605: Subject: 25.1.50; form-at-point might fail for some THINGS Tino Calancha
@ 2016-10-05 1:15 ` npostavs
2016-10-05 3:35 ` Tino Calancha
2016-10-06 7:13 ` Andreas Röhler
2016-10-11 2:53 ` Tino Calancha
2 siblings, 1 reply; 11+ messages in thread
From: npostavs @ 2016-10-05 1:15 UTC (permalink / raw)
To: Tino Calancha; +Cc: 24605
tags 24605 patch
severity 24605 minor
quit
Tino Calancha <tino.calancha@gmail.com> writes:
> Because `thing-at-point' doesn't return always a string, as
> `form-at-point' currently assumes.
[...]
>
> (with-temp-buffer
> (require 'thingatpt)
> (insert "1")
> (let ((res
> (cond ((and (number-at-point)
> (form-at-point 'number)) 0)
> ((and (number-at-point)
> (not (form-at-point 'number))) -1)
> ((and (not (number-at-point))
> (form-at-point 'number)) -2)
> ((and (not (number-at-point))
> (not (form-at-point 'number))) -3))))
> (pcase res
> ('0 (message "OK, both 'number-at-point and 'form-at-point successfull"))
> (-1 (message "'number-at-point' works but (form-at-point 'number) fails"))
> (-2 (message "(form-at-point 'number) works but 'number-at-point' fails"))
> (-3 (message "Both 'number-at-point' and (form-at-point 'number) fails")))))
> => "’number-at-point’ works but (form-at-point ’number) fails"
Well, it looks like `form-at-point' was assumed to be used only for
implementing the foo-at-point functions, (form-at-point 'sexp 'numberp)
does work fine for this. But we may as well let (form-at-point 'number)
work too, since it's the more obvious way to call it.
> (defun form-at-point (&optional thing pred)
> - (let ((sexp (ignore-errors
> - (thing-at-point--read-from-whole-string
> - (thing-at-point (or thing 'sexp))))))
> + (let* ((obj (thing-at-point (or thing 'sexp)))
> + (sexp (ignore-errors
> + (if (stringp obj)
> + (thing-at-point--read-from-whole-string obj)
> + obj))))
I suggest keeping the `ignore-errors' strictly around the
`thing-at-point--read-from-whole-string' call.
> (if (or (not pred) (funcall pred sexp)) sexp)))
^ permalink raw reply [flat|nested] 11+ messages in thread
* bug#24605: Subject: 25.1.50; form-at-point might fail for some THINGS
2016-10-05 1:15 ` npostavs
@ 2016-10-05 3:35 ` Tino Calancha
2016-10-05 11:50 ` Noam Postavsky
0 siblings, 1 reply; 11+ messages in thread
From: Tino Calancha @ 2016-10-05 3:35 UTC (permalink / raw)
To: npostavs; +Cc: 24605, Tino Calancha
Thank you for the e-mail.
On Tue, 4 Oct 2016, npostavs@users.sourceforge.net wrote:
> Well, it looks like `form-at-point' was assumed to be used only for
> implementing the foo-at-point functions, (form-at-point 'sexp 'numberp)
> does work fine for this. But we may as well let (form-at-point 'number)
> work too, since it's the more obvious way to call it.
In my case i use lib thingatpt+, so i have:
(get 'list 'thing-at-point)
=> tap-list-at-point
That causes `list-at-point' always fails regardless on where
it is the point, for the same reason: `tap-list-at-point' returns
a cons not an string.
> I suggest keeping the `ignore-errors' strictly around the
> `thing-at-point--read-from-whole-string' call.
Ok, corrected the patch:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
From ea4c09df929451f4268ea4d608ee11bb4249854f Mon Sep 17 00:00:00 2001
From: Tino Calancha <tino.calancha@gmail.com>
Date: Wed, 5 Oct 2016 12:25:07 +0900
Subject: [PATCH] form-at-point work for all kind of THINGS
* lisp/thingatpt.el (form-at-point):
Use thing-at-point--read-from-whole-string only if thing-at-point
returns a string (Bug#24605).
---
lisp/thingatpt.el | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/lisp/thingatpt.el b/lisp/thingatpt.el
index df5c52d..6d1014b 100644
--- a/lisp/thingatpt.el
+++ b/lisp/thingatpt.el
@@ -586,9 +586,11 @@ 'read-from-whole-string
"This is an internal thingatpt function and should not be used.")
(defun form-at-point (&optional thing pred)
- (let ((sexp (ignore-errors
- (thing-at-point--read-from-whole-string
- (thing-at-point (or thing 'sexp))))))
+ (let* ((obj (thing-at-point (or thing 'sexp)))
+ (sexp (if (stringp obj)
+ (ignore-errors
+ (thing-at-point--read-from-whole-string obj))
+ obj)))
(if (or (not pred) (funcall pred sexp)) sexp)))
;;;###autoload
--
2.9.3
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
In GNU Emacs 25.1.50.1 (x86_64-pc-linux-gnu, GTK+ Version 3.22.0)
of 2016-10-04 built on calancha-pc
Repository revision: e2913dc880b9843bf69cf885270551bafeb46120
^ permalink raw reply related [flat|nested] 11+ messages in thread
* bug#24605: Subject: 25.1.50; form-at-point might fail for some THINGS
2016-10-05 3:35 ` Tino Calancha
@ 2016-10-05 11:50 ` Noam Postavsky
2016-10-05 12:30 ` Tino Calancha
0 siblings, 1 reply; 11+ messages in thread
From: Noam Postavsky @ 2016-10-05 11:50 UTC (permalink / raw)
To: Tino Calancha; +Cc: 24605
On Tue, Oct 4, 2016 at 11:35 PM, Tino Calancha <tino.calancha@gmail.com> wrote:
> Ok, corrected the patch:
Looks good to me.
^ permalink raw reply [flat|nested] 11+ messages in thread
* bug#24605: Subject: 25.1.50; form-at-point might fail for some THINGS
2016-10-05 11:50 ` Noam Postavsky
@ 2016-10-05 12:30 ` Tino Calancha
2016-10-05 12:38 ` Tino Calancha
0 siblings, 1 reply; 11+ messages in thread
From: Tino Calancha @ 2016-10-05 12:30 UTC (permalink / raw)
To: Noam Postavsky; +Cc: 24605, Tino Calancha
On Wed, 5 Oct 2016, Noam Postavsky wrote:
> On Tue, Oct 4, 2016 at 11:35 PM, Tino Calancha <tino.calancha@gmail.com> wrote:
>> Ok, corrected the patch:
>
> Looks good to me.
Thank you very much.
I will push it to master branch in a few days if i don't see further
comments.
^ permalink raw reply [flat|nested] 11+ messages in thread
* bug#24605: Subject: 25.1.50; form-at-point might fail for some THINGS
2016-10-05 12:30 ` Tino Calancha
@ 2016-10-05 12:38 ` Tino Calancha
2016-10-05 13:09 ` Eli Zaretskii
0 siblings, 1 reply; 11+ messages in thread
From: Tino Calancha @ 2016-10-05 12:38 UTC (permalink / raw)
To: Tino Calancha; +Cc: 24605, Noam Postavsky
On Wed, 5 Oct 2016, Tino Calancha wrote:
>> Looks good to me.
> Thank you very much.
> I will push it to master branch in a few days if i don't see further
> comments.
Opps i said master because i am too used to say that.
Probably the fix should go to the emacs-25 branch, right?
^ permalink raw reply [flat|nested] 11+ messages in thread
* bug#24605: Subject: 25.1.50; form-at-point might fail for some THINGS
2016-10-05 12:38 ` Tino Calancha
@ 2016-10-05 13:09 ` Eli Zaretskii
2016-10-05 13:52 ` Tino Calancha
0 siblings, 1 reply; 11+ messages in thread
From: Eli Zaretskii @ 2016-10-05 13:09 UTC (permalink / raw)
To: Tino Calancha; +Cc: 24605, npostavs
> From: Tino Calancha <tino.calancha@gmail.com>
> Date: Wed, 5 Oct 2016 21:38:16 +0900 (JST)
> Cc: 24605@debbugs.gnu.org, Noam Postavsky <npostavs@users.sourceforge.net>
>
> > I will push it to master branch in a few days if i don't see further
> > comments.
> Opps i said master because i am too used to say that.
> Probably the fix should go to the emacs-25 branch, right?
It depends on when was this problem introduced. Can you tell?
^ permalink raw reply [flat|nested] 11+ messages in thread
* bug#24605: Subject: 25.1.50; form-at-point might fail for some THINGS
2016-10-05 13:09 ` Eli Zaretskii
@ 2016-10-05 13:52 ` Tino Calancha
2016-10-05 15:59 ` Eli Zaretskii
0 siblings, 1 reply; 11+ messages in thread
From: Tino Calancha @ 2016-10-05 13:52 UTC (permalink / raw)
To: Eli Zaretskii; +Cc: 24605, Tino Calancha, npostavs
On Wed, 5 Oct 2016, Eli Zaretskii wrote:
>> From: Tino Calancha <tino.calancha@gmail.com>
>> Date: Wed, 5 Oct 2016 21:38:16 +0900 (JST)
>> Cc: 24605@debbugs.gnu.org, Noam Postavsky <npostavs@users.sourceforge.net>
>>
>>> I will push it to master branch in a few days if i don't see further
>>> comments.
>> Opps i said master because i am too used to say that.
>> Probably the fix should go to the emacs-25 branch, right?
>
> It depends on when was this problem introduced. Can you tell?
The problem in my snippet code appear since commit 748b0d84 (Emacs-24).
That solves my question: it should go to the master branch.
Thank you.
^ permalink raw reply [flat|nested] 11+ messages in thread
* bug#24605: Subject: 25.1.50; form-at-point might fail for some THINGS
2016-10-05 13:52 ` Tino Calancha
@ 2016-10-05 15:59 ` Eli Zaretskii
0 siblings, 0 replies; 11+ messages in thread
From: Eli Zaretskii @ 2016-10-05 15:59 UTC (permalink / raw)
To: Tino Calancha; +Cc: 24605, npostavs
> From: Tino Calancha <tino.calancha@gmail.com>
> Date: Wed, 5 Oct 2016 22:52:37 +0900 (JST)
> cc: Tino Calancha <tino.calancha@gmail.com>, 24605@debbugs.gnu.org,
> npostavs@users.sourceforge.net
>
> > It depends on when was this problem introduced. Can you tell?
> The problem in my snippet code appear since commit 748b0d84 (Emacs-24).
> That solves my question: it should go to the master branch.
Right, thanks.
^ permalink raw reply [flat|nested] 11+ messages in thread
* bug#24605: Subject: 25.1.50; form-at-point might fail for some THINGS
2016-10-04 6:22 bug#24605: Subject: 25.1.50; form-at-point might fail for some THINGS Tino Calancha
2016-10-05 1:15 ` npostavs
@ 2016-10-06 7:13 ` Andreas Röhler
2016-10-11 2:53 ` Tino Calancha
2 siblings, 0 replies; 11+ messages in thread
From: Andreas Röhler @ 2016-10-06 7:13 UTC (permalink / raw)
To: 24605
On 04.10.2016 08:22, Tino Calancha wrote:
> (with-temp-buffer
> (require 'thingatpt)
> (insert "1")
An interesting test-case would be
(with-temp-buffer
(require 'thingatpt)
(insert "1a")
(forward-char -1)
...
Than cursor is at "a" and every form fails.
Same with (forward-char -2)
^ permalink raw reply [flat|nested] 11+ messages in thread
* bug#24605: Subject: 25.1.50; form-at-point might fail for some THINGS
2016-10-04 6:22 bug#24605: Subject: 25.1.50; form-at-point might fail for some THINGS Tino Calancha
2016-10-05 1:15 ` npostavs
2016-10-06 7:13 ` Andreas Röhler
@ 2016-10-11 2:53 ` Tino Calancha
2 siblings, 0 replies; 11+ messages in thread
From: Tino Calancha @ 2016-10-11 2:53 UTC (permalink / raw)
To: 24605-done
Noam Postavsky <npostavs@users.sourceforge.net> writes:
> Looks good to me.
Pushed fix to master as commit 9640e9f4
^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~2016-10-11 2:53 UTC | newest]
Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-10-04 6:22 bug#24605: Subject: 25.1.50; form-at-point might fail for some THINGS Tino Calancha
2016-10-05 1:15 ` npostavs
2016-10-05 3:35 ` Tino Calancha
2016-10-05 11:50 ` Noam Postavsky
2016-10-05 12:30 ` Tino Calancha
2016-10-05 12:38 ` Tino Calancha
2016-10-05 13:09 ` Eli Zaretskii
2016-10-05 13:52 ` Tino Calancha
2016-10-05 15:59 ` Eli Zaretskii
2016-10-06 7:13 ` Andreas Röhler
2016-10-11 2:53 ` Tino Calancha
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
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).