all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* function-called-at-point: ignore-errors around find-tag-default
@ 2005-02-14  4:31 Karl Chen
  2005-02-14 13:40 ` Stefan Monnier
  2005-02-15  6:15 ` Richard Stallman
  0 siblings, 2 replies; 7+ messages in thread
From: Karl Chen @ 2005-02-14  4:31 UTC (permalink / raw)



Hi, 

In some modes (tex-mode), `find-tag-default' can misbehave and
error.

It is annoying if you cannot `describe-function' or
`describe-variable' in such a mode, so I propose the following
patch.  (`function-called-at-point' and `variable-at-point'
already use condition-cases.  But an alternative would be to wrap
`find-tag-default' itself in a condition-case.)


--- /usr/local/stow/emacs-cvs/share/emacs/22.0.50/lisp/.backup/help.el.~1~	2005-02-09 22:46:42.000000000 -0800
+++ /usr/local/stow/emacs-cvs/share/emacs/22.0.50/lisp/help.el	2005-02-13 20:10:05.000000000 -0800
@@ -273,7 +273,7 @@
 		    (let ((obj (read (current-buffer))))
 		      (and (symbolp obj) (fboundp obj) obj))))
 	      (error nil))))
-      (let* ((str (find-tag-default))
+      (let* ((str (condition-case () (find-tag-default) (error nil)))
 	     (sym (if str (intern-soft str))))
 	(if (and sym (fboundp sym))
 	    sym


--- /usr/local/stow/emacs-cvs/share/emacs/22.0.50/lisp/.backup/help-fns.el.~1~	2005-02-03 11:41:14.000000000 -0800
+++ /usr/local/stow/emacs-cvs/share/emacs/22.0.50/lisp/help-fns.el	2005-02-13 20:20:59.000000000 -0800
@@ -487,7 +487,7 @@
 	      (let ((obj (read (current-buffer))))
 		(and (symbolp obj) (boundp obj) obj))))
 	(error nil))
-      (let* ((str (find-tag-default))
+      (let* ((str (condition-case () (find-tag-default) (error nil)))
 	     (sym (if str (intern-soft str))))
 	(if (and sym (or any-symbol (boundp sym)))
 	    sym

-- 
Karl 2005-02-13 20:24

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: function-called-at-point: ignore-errors around find-tag-default
  2005-02-14  4:31 function-called-at-point: ignore-errors around find-tag-default Karl Chen
@ 2005-02-14 13:40 ` Stefan Monnier
  2005-02-14 19:06   ` Karl Chen
  2005-02-15  6:15 ` Richard Stallman
  1 sibling, 1 reply; 7+ messages in thread
From: Stefan Monnier @ 2005-02-14 13:40 UTC (permalink / raw)
  Cc: Emacs Developement List

> In some modes (tex-mode), `find-tag-default' can misbehave and error.

To better judge which is the right thing to do, could you describe what kind
of misbehavior/error can happen and in which circumstance?


        Stefan

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: function-called-at-point: ignore-errors around find-tag-default
  2005-02-14 13:40 ` Stefan Monnier
@ 2005-02-14 19:06   ` Karl Chen
  0 siblings, 0 replies; 7+ messages in thread
From: Karl Chen @ 2005-02-14 19:06 UTC (permalink / raw)


>>>>> On 2005-02-14 05:40 PST, Stefan Monnier writes:

    >> In some modes (tex-mode), `find-tag-default' can misbehave
    >> and error.
    Stefan> To better judge which is the right thing to do, could
    Stefan> you describe what kind of misbehavior/error can happen
    Stefan> and in which circumstance?

Sure.  

Using `tex-mode' from textmodes/tex-mode.el (rather than from
AUCTeX):

(find-file "/tmp/a.tex")
(insert "\begin")
(find-tag-default)  ; on the same line as "\begin"

Error: scan-error; Data: (Containing expression ends prematurely 2 2)

This happens because tex-mode defines a function for
`forward-sexp-function' which looks for "\end".
`find-tag-default' assumes the regular forward-sexp function which
only considers single-character syntaxes (and thus would never
error if point is after \(\sw\|\s_\)+ )


-- 
Karl 2005-02-14 10:55

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: function-called-at-point: ignore-errors around find-tag-default
  2005-02-14  4:31 function-called-at-point: ignore-errors around find-tag-default Karl Chen
  2005-02-14 13:40 ` Stefan Monnier
@ 2005-02-15  6:15 ` Richard Stallman
  2005-02-17  3:56   ` Karl Chen
  1 sibling, 1 reply; 7+ messages in thread
From: Richard Stallman @ 2005-02-15  6:15 UTC (permalink / raw)
  Cc: emacs-devel

    In some modes (tex-mode), `find-tag-default' can misbehave and
    error.

It should never get an error--if it can't find a suitable recommendation,
it should return nil.

      But an alternative would be to wrap
    `find-tag-default' itself in a condition-case.)

Before we do that, we should debug it and try fixing the bug
that makes it get an error.  Would you like to debug it?

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: function-called-at-point: ignore-errors around find-tag-default
  2005-02-15  6:15 ` Richard Stallman
@ 2005-02-17  3:56   ` Karl Chen
  2005-02-17 13:14     ` Stefan Monnier
  2005-02-17 23:09     ` Richard Stallman
  0 siblings, 2 replies; 7+ messages in thread
From: Karl Chen @ 2005-02-17  3:56 UTC (permalink / raw)


>>>>> On 2005-02-14 22:15 PST, Richard Stallman writes:

    rms> It should never get an error--if it can't find a suitable
    rms> recommendation, it should return nil.

    rms>       But an alternative would be to wrap
    rms>     `find-tag-default' itself in a condition-case.)

    rms> Before we do that, we should debug it and try fixing the
    rms> bug that makes it get an error.  Would you like to debug
    rms> it?

I already debugged it as in my other post in this thread:
(forward-sexp -1) errors when it is in the middle of a sexp.
Since `forward-sexp' calls a user-defined function which can
behave unpredictably, I think the best thing is to wrap something
(i.e. `find-tag-default' or all its callers) in condition-case.


--- /usr/local/stow/emacs-cvs/share/emacs/22.0.50/lisp/.backup/subr.el.~1~	2005-02-09 07:50:41.000000000 -0800
+++ /usr/local/stow/emacs-cvs/share/emacs/22.0.50/lisp/subr.el	2005-02-16 19:50:57.000000000 -0800
@@ -1969,13 +1969,15 @@
 	    (re-search-forward "\\(\\sw\\|\\s_\\)+"
 			       (save-excursion (end-of-line) (point))
 			       t))
-	(progn (goto-char (match-end 0))
-	       (buffer-substring-no-properties
-                (point)
-                (progn (forward-sexp -1)
-                       (while (looking-at "\\s'")
-                         (forward-char 1))
-                       (point))))
+	(condition-case nil
+            (progn (goto-char (match-end 0))
+                   (buffer-substring-no-properties
+                    (point)
+                    (progn (forward-sexp -1)
+                           (while (looking-at "\\s'")
+                             (forward-char 1))
+                           (point))))
+          (error nil))
       nil)))
 
 (defmacro with-syntax-table (table &rest body)



-- 
Karl 2005-02-16 19:52

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: function-called-at-point: ignore-errors around find-tag-default
  2005-02-17  3:56   ` Karl Chen
@ 2005-02-17 13:14     ` Stefan Monnier
  2005-02-17 23:09     ` Richard Stallman
  1 sibling, 0 replies; 7+ messages in thread
From: Stefan Monnier @ 2005-02-17 13:14 UTC (permalink / raw)
  Cc: emacs-devel

> --- /usr/local/stow/emacs-cvs/share/emacs/22.0.50/lisp/.backup/subr.el.~1~	2005-02-09 07:50:41.000000000 -0800
> +++ /usr/local/stow/emacs-cvs/share/emacs/22.0.50/lisp/subr.el	2005-02-16 19:50:57.000000000 -0800
> @@ -1969,13 +1969,15 @@
>  	    (re-search-forward "\\(\\sw\\|\\s_\\)+"
>  			       (save-excursion (end-of-line) (point))
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
                               (line-end-position)

>  			       t))
> -	(progn (goto-char (match-end 0))
> -	       (buffer-substring-no-properties
> -                (point)
> -                (progn (forward-sexp -1)
> -                       (while (looking-at "\\s'")
> -                         (forward-char 1))
> -                       (point))))
> +	(condition-case nil
> +            (progn (goto-char (match-end 0))
> +                   (buffer-substring-no-properties
> +                    (point)
> +                    (progn (forward-sexp -1)
> +                           (while (looking-at "\\s'")
> +                             (forward-char 1))
> +                           (point))))
> +          (error nil))
>        nil)))
 
I recommend to only catch "scan-error" so as not to hide other potential
bugs.  But maybe a better fix is to let-bind forward-sexp-function to nil
around the call to forward-sexp.  After all, we're using here forward-sexp
to skip over a symbol, not just any a sexp.  Or maybe even replace
forward-sexp with (skip-syntax-backward "w_"), although it seems so obvious
that maybe there's a reason why it's not done: better check the file's log
to seen if it wasn't (skip-syntax-backward "w_") already in the past.


        Stefan

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: function-called-at-point: ignore-errors around find-tag-default
  2005-02-17  3:56   ` Karl Chen
  2005-02-17 13:14     ` Stefan Monnier
@ 2005-02-17 23:09     ` Richard Stallman
  1 sibling, 0 replies; 7+ messages in thread
From: Richard Stallman @ 2005-02-17 23:09 UTC (permalink / raw)
  Cc: emacs-devel

    I already debugged it as in my other post in this thread:
    (forward-sexp -1) errors when it is in the middle of a sexp.
    Since `forward-sexp' calls a user-defined function which can
    behave unpredictably, I think the best thing is to wrap something
    (i.e. `find-tag-default' or all its callers) in condition-case.

Ok, now that I see the precise problem, I agree with you.

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2005-02-17 23:09 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-02-14  4:31 function-called-at-point: ignore-errors around find-tag-default Karl Chen
2005-02-14 13:40 ` Stefan Monnier
2005-02-14 19:06   ` Karl Chen
2005-02-15  6:15 ` Richard Stallman
2005-02-17  3:56   ` Karl Chen
2005-02-17 13:14     ` Stefan Monnier
2005-02-17 23:09     ` Richard Stallman

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.