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