all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* 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

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 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.