unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* Why post-command-hook so difficult to debug?
@ 2012-07-22  2:40 Leo
  2012-08-23 18:37 ` Tassilo Horn
  2012-08-29  3:33 ` Stefan Monnier
  0 siblings, 2 replies; 9+ messages in thread
From: Leo @ 2012-07-22  2:40 UTC (permalink / raw)
  To: emacs-devel

For example, some days ago I was seeing this error:

Error in post-command-hook (completion-in-region--postch): (wrong-type-argument characterp 134217855)

and it turned out the error was generated by another function 100 miles
from completion-in-region--postch. debug-on-error is mostly useless in
this case.

Can post-command-hook errors be more informative? Thanks.

Leo




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

* Re: Why post-command-hook so difficult to debug?
  2012-07-22  2:40 Why post-command-hook so difficult to debug? Leo
@ 2012-08-23 18:37 ` Tassilo Horn
  2012-08-23 23:39   ` Leo
  2012-08-29  3:33 ` Stefan Monnier
  1 sibling, 1 reply; 9+ messages in thread
From: Tassilo Horn @ 2012-08-23 18:37 UTC (permalink / raw)
  To: Leo; +Cc: emacs-devel

Leo <sdl.web@gmail.com> writes:

Hi Leo!

> For example, some days ago I was seeing this error:
>
> Error in post-command-hook (completion-in-region--postch): (wrong-type-argument characterp 134217855)
>
> and it turned out the error was generated by another function 100 miles
> from completion-in-region--postch.  debug-on-error is mostly useless in
> this case.

I'm having a very similar error right now, 

  Error in post-command-hook (completion-in-region--postch):
    (wrong-type-argument stringp nil)

I've stared at the definition of `completion-in-region--postch', and
probably the error happens in the the form:

    (funcall completion-in-region-mode--predicate)

Of course, now I can't reproduce it anymore... :-(

Anyway, could you please elaborate what was the 100 miles away function
in your case?  Maybe it's similar here...

Bye,
Tassilo



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

* Re: Why post-command-hook so difficult to debug?
  2012-08-23 18:37 ` Tassilo Horn
@ 2012-08-23 23:39   ` Leo
  2012-08-24  6:11     ` Tassilo Horn
  0 siblings, 1 reply; 9+ messages in thread
From: Leo @ 2012-08-23 23:39 UTC (permalink / raw)
  To: emacs-devel

On 2012-08-24 02:37 +0800, Tassilo Horn wrote:
> Anyway, could you please elaborate what was the 100 miles away function
> in your case?  Maybe it's similar here...

Check the entries in completion-at-point-functions.

Leo




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

* Re: Why post-command-hook so difficult to debug?
  2012-08-23 23:39   ` Leo
@ 2012-08-24  6:11     ` Tassilo Horn
  2012-08-24  6:41       ` Leo
  0 siblings, 1 reply; 9+ messages in thread
From: Tassilo Horn @ 2012-08-24  6:11 UTC (permalink / raw)
  To: Leo; +Cc: emacs-devel

Leo <sdl.web@gmail.com> writes:

> On 2012-08-24 02:37 +0800, Tassilo Horn wrote:
>> Anyway, could you please elaborate what was the 100 miles away function
>> in your case?  Maybe it's similar here...
>
> Check the entries in completion-at-point-functions.

,----
| completion-at-point-functions is a variable defined in `minibuffer.el'.
| Its value is (nrepl-complete-at-point tags-completion-at-point-function)
`----

`nrepl-complete-at-point' is the completion at point function I've just
written.  To my best understanding and debugging, it always returns
completely valid

  (START END (COMPLETION-STRING-LIST))

triples or nil if there's no completion.  The definition is

--8<---------------cut here---------------start------------->8---
(defun nrepl-complete-at-point ()
  (interactive)
  (let ((sap (symbol-at-point)))
    (when (and sap (not (in-string-p)))
      (nrepl-send-string "(require 'complete.core)" "user" 'identity)
      (let ((form (format "(complete.core/completions \"%s\" *ns*)" sap))
	    (bounds (bounds-of-thing-at-point 'symbol)))
	(let ((completions (car (read-from-string
				 (plist-get (nrepl-send-string-sync form nrepl-buffer-ns)
					    :value)))))
	  (when completions
	    (list (car bounds) (cdr bounds) completions)))))))
--8<---------------cut here---------------end--------------->8---

For example, I have (ide|) in my clojure buffer and try to complete (|
is point, here).  The function returns

  (1232 1235 ("identical?" "identity"))

and the common prefix is completed: (identi).  Then, my function is
immediately ran again (why?) and my function returns

  (1232 1238 ("identical?" "identity"))

1235 and 1238 are the current location of point in these examples.

I tried removing `tags-completion-at-point-function' from
`completion-at-point-functions' but the error persists.  So it seems I'm
the culprit although I cannot spot the problem...

Bye,
Tassilo



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

* Re: Why post-command-hook so difficult to debug?
  2012-08-24  6:11     ` Tassilo Horn
@ 2012-08-24  6:41       ` Leo
  2012-08-24  6:58         ` Tassilo Horn
  0 siblings, 1 reply; 9+ messages in thread
From: Leo @ 2012-08-24  6:41 UTC (permalink / raw)
  To: emacs-devel

On 2012-08-24 14:11 +0800, Tassilo Horn wrote:
> I tried removing `tags-completion-at-point-function' from
> `completion-at-point-functions' but the error persists.  So it seems I'm
> the culprit although I cannot spot the problem...

Are you sure that nrepl-send-string-sync returns all completions in
strings?

Leo




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

* Re: Why post-command-hook so difficult to debug?
  2012-08-24  6:41       ` Leo
@ 2012-08-24  6:58         ` Tassilo Horn
  2012-08-24  7:59           ` Leo
  0 siblings, 1 reply; 9+ messages in thread
From: Tassilo Horn @ 2012-08-24  6:58 UTC (permalink / raw)
  To: Leo; +Cc: emacs-devel

Leo <sdl.web@gmail.com> writes:

>> I tried removing `tags-completion-at-point-function' from
>> `completion-at-point-functions' but the error persists.  So it seems I'm
>> the culprit although I cannot spot the problem...
>
> Are you sure that nrepl-send-string-sync returns all completions in
> strings?

Yes.  To be extra sure, I added a

  (assert (null (remove-if 'stringp completions)))

which doesn't trigger any error, but the error in
`completion-in-region--postch' is still there...

Bye,
Tassilo



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

* Re: Why post-command-hook so difficult to debug?
  2012-08-24  6:58         ` Tassilo Horn
@ 2012-08-24  7:59           ` Leo
  2012-08-24  8:12             ` Tassilo Horn
  0 siblings, 1 reply; 9+ messages in thread
From: Leo @ 2012-08-24  7:59 UTC (permalink / raw)
  To: emacs-devel

On 2012-08-24 14:58 +0800, Tassilo Horn wrote:
> Yes.  To be extra sure, I added a
>
>   (assert (null (remove-if 'stringp completions)))
>
> which doesn't trigger any error, but the error in
> `completion-in-region--postch' is still there...

In that case I have no idea. I was lucky because I found the error in
the completion functions. post-command-hook is difficult to debug (I did
it by guesswork).

Leo




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

* Re: Why post-command-hook so difficult to debug?
  2012-08-24  7:59           ` Leo
@ 2012-08-24  8:12             ` Tassilo Horn
  0 siblings, 0 replies; 9+ messages in thread
From: Tassilo Horn @ 2012-08-24  8:12 UTC (permalink / raw)
  To: Leo; +Cc: emacs-devel

Leo <sdl.web@gmail.com> writes:

>> Yes.  To be extra sure, I added a
>>
>>   (assert (null (remove-if 'stringp completions)))
>>
>> which doesn't trigger any error, but the error in
>> `completion-in-region--postch' is still there...
>
> In that case I have no idea. I was lucky because I found the error in
> the completion functions.

Thanks anyway.

> post-command-hook is difficult to debug (I did it by guesswork).

Ditto, but I'm running out of guesses.  I'll open a new specific thread
about this issue then.

Bye,
Tassilo



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

* Re: Why post-command-hook so difficult to debug?
  2012-07-22  2:40 Why post-command-hook so difficult to debug? Leo
  2012-08-23 18:37 ` Tassilo Horn
@ 2012-08-29  3:33 ` Stefan Monnier
  1 sibling, 0 replies; 9+ messages in thread
From: Stefan Monnier @ 2012-08-29  3:33 UTC (permalink / raw)
  To: Leo; +Cc: emacs-devel

> For example, some days ago I was seeing this error:
> Error in post-command-hook (completion-in-region--postch):
> (wrong-type-argument characterp 134217855)

> and it turned out the error was generated by another function 100 miles
> from completion-in-region--postch. debug-on-error is mostly useless in
> this case.

> Can post-command-hook errors be more informative? Thanks.

Well, we could make debug-on-error work in post-command-hook, but that
will take some work.  If someone's interested, here are the problems to
solve:
- post-command-hook is run (via safe_run_hooks) in the equivalent of a
  (condition-case nil ... (t nil)), so debug-on-error is ignored because
  the errors are caught.  Maybe we can change debug-on-error to enter
  the debugger (rather than stay passive) when an error is caught by
  a `t' rather than by an `error' handler.
- post-command-hook is also run in the debugger, so in order to avoid
  recursively entering the debugger, we'll need to remove the currently
  executing function from post-command-hook before entering
  the debugger.
  I think the best way to do that is to add a new hook
  debug-let-bindings-functions whose functions return lists of (VAR
  . VAL) pairs that should be re-bound during debugging.  This way
  safe_run_hooks can add such a function to cause the current hook to be
  rebound temporarily with the debugged function removed.


-- Stefan



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

end of thread, other threads:[~2012-08-29  3:33 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-07-22  2:40 Why post-command-hook so difficult to debug? Leo
2012-08-23 18:37 ` Tassilo Horn
2012-08-23 23:39   ` Leo
2012-08-24  6:11     ` Tassilo Horn
2012-08-24  6:41       ` Leo
2012-08-24  6:58         ` Tassilo Horn
2012-08-24  7:59           ` Leo
2012-08-24  8:12             ` Tassilo Horn
2012-08-29  3:33 ` Stefan Monnier

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