unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* Error in post-command-hook (completion-in-region--postch): (wrong-type-argument stringp nil)
@ 2012-08-24  8:25 Tassilo Horn
  2012-08-24  9:44 ` Thien-Thi Nguyen
  2012-08-24 15:46 ` Stefan Monnier
  0 siblings, 2 replies; 9+ messages in thread
From: Tassilo Horn @ 2012-08-24  8:25 UTC (permalink / raw)
  To: emacs-devel

Hi all,

I'm writing a completion at point function for nREPL (which is about the
same as SLIME/Swank is for Common Lisp).  However, if my function is in
`completion-at-point-functions' I frequently get the error in the
subject, and as a annoying result `completion-in-region-mode' isn't
toggled off anymore.

I've read the docs about completion at point several times, and my
function looks good to me.  It'll always return

  (START END (LIST-OF-STRINGS))

with valid positions and the completions really being strings, or nil if
there's no possible completion.

--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
	    ;; TODO: Remove me again!
	    (assert (null (remove-if 'stringp completions)))
	    (list (car bounds) (cdr bounds) completions)))))))
--8<---------------cut here---------------end--------------->8---


Looking at the definition of `completion-in-region--postch' the only
place where the error might be triggered is in the

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

line.  The value of that is

--8<---------------cut here---------------start------------->8---
completion-in-region-mode--predicate is a variable defined in `minibuffer.el'.
Its value is #[0 "\301 \242\300=\207"
    [9284 nrepl-complete-at-point]
    2 "\n\n(fn)"]
--8<---------------cut here---------------end--------------->8---

There are no other function in `completion-at-point-functions'.

I'm happy for any pointers!

Bye,
Tassilo



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

* Re: Error in post-command-hook (completion-in-region--postch): (wrong-type-argument stringp nil)
  2012-08-24  8:25 Error in post-command-hook (completion-in-region--postch): (wrong-type-argument stringp nil) Tassilo Horn
@ 2012-08-24  9:44 ` Thien-Thi Nguyen
  2012-08-24 11:23   ` Tassilo Horn
  2012-08-24 15:46 ` Stefan Monnier
  1 sibling, 1 reply; 9+ messages in thread
From: Thien-Thi Nguyen @ 2012-08-24  9:44 UTC (permalink / raw)
  To: emacs-devel

[-- Attachment #1: Type: text/plain, Size: 1200 bytes --]

() Tassilo Horn <tsdh@gnu.org>
() Fri, 24 Aug 2012 10:25:37 +0200

   (defun nrepl-complete-at-point ()
     (interactive)
     (let ((sap (symbol-at-point)))
       (when (and sap (not (in-string-p)))
         (nrepl-send-string [...])
         [...]
         )))

   I'm happy for any pointers!

Many times, the value of a variable depends on the current buffer.
(This is the beauty and curse of Emacs.)

Does ‘nrepl-send-string’ change the current buffer?
If so, does it change it back?
If not, what does it assume about the current buffer?

The same questions could apply to any of the functions involved.

To find out, i would add some calls to ‘message’, not trusting builtin
debug, Edebug (or, more to the point, my fumblings w/ these facilities)
to not distort the state under study.
-- 
Thien-Thi Nguyen ..................................... GPG key: 4C807502
.                  NB: ttn at glug dot org is not me                   .
.                 (and has not been since 2007 or so)                  .
.                        ACCEPT NO SUBSTITUTES                         .
........... please send technical questions to mailing lists ...........

[-- Attachment #2: Type: application/pgp-signature, Size: 197 bytes --]

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

* Re: Error in post-command-hook (completion-in-region--postch): (wrong-type-argument stringp nil)
  2012-08-24  9:44 ` Thien-Thi Nguyen
@ 2012-08-24 11:23   ` Tassilo Horn
  2012-08-24 13:07     ` Thien-Thi Nguyen
  0 siblings, 1 reply; 9+ messages in thread
From: Tassilo Horn @ 2012-08-24 11:23 UTC (permalink / raw)
  To: Thien-Thi Nguyen; +Cc: emacs-devel

Thien-Thi Nguyen <ttn@gnuvola.org> writes:

>    (defun nrepl-complete-at-point ()
>      (interactive)
>      (let ((sap (symbol-at-point)))
>        (when (and sap (not (in-string-p)))
>          (nrepl-send-string [...])
>          [...]
>          )))
>
>    I'm happy for any pointers!
>
> Many times, the value of a variable depends on the current buffer.
> (This is the beauty and curse of Emacs.)
>
> Does ‘nrepl-send-string’ change the current buffer?

No.

> The same questions could apply to any of the functions involved.
>
> To find out, i would add some calls to ‘message’, not trusting builtin
> debug, Edebug (or, more to the point, my fumblings w/ these facilities)
> to not distort the state under study.

I tried that, and message always said I'm in the buffer I was supposed
to be in, even though the next message was the error.

To be super-safe I added

    (assert (eq major-mode 'clojure-mode))

before every single form of my function!  Right now, I only have one
clojure-mode buffer open.  The original post-command-hook error still
occurs, but the assertions are always true anyhow.  So it doesn't seem
to be caused by being in the wrong buffer...

Bye,
Tassilo



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

* Re: Error in post-command-hook (completion-in-region--postch): (wrong-type-argument stringp nil)
  2012-08-24 11:23   ` Tassilo Horn
@ 2012-08-24 13:07     ` Thien-Thi Nguyen
  2012-08-24 16:23       ` Tassilo Horn
  0 siblings, 1 reply; 9+ messages in thread
From: Thien-Thi Nguyen @ 2012-08-24 13:07 UTC (permalink / raw)
  To: emacs-devel

[-- Attachment #1: Type: text/plain, Size: 1933 bytes --]

() Tassilo Horn <tsdh@gnu.org>
() Fri, 24 Aug 2012 13:23:05 +0200

   > Does ‘nrepl-send-string’ change the current buffer?

   No.

   > The same questions could apply to any of the functions involved.

Did you check the other functions?  (If not, before you do, see below.)

   > [use ‘message’]

Sorry, i was not clear.  I would use ‘message’ in several places, each
w/ a unique format string (to avoid Emacs combining them in *Messages*),
to trace the execution path.  That would help answer some aux questions:
Did the function finish?  Did it return the form as expected?

   I tried that, and message always said I'm in the buffer I was
   supposed to be in, even though the next message was the error.

   To be super-safe I added

       (assert (eq major-mode 'clojure-mode))

   before every single form of my function!  Right now, I only have one
   clojure-mode buffer open.  The original post-command-hook error still
   occurs, but the assertions are always true anyhow.  So it doesn't
   seem to be caused by being in the wrong buffer...

With the series-of-‘message’ calls "instrumentation", i would expand the
set of interesting state to check other assumptions.  I see several vars
that are ‘let’-bound in minibuffer.el that are good candidates.

Sort of in parallel (maybe you found a bug in Emacs!), i would also try
a trivial func that does no computation and returns constant, known
data, likewise "instrumented", to validate the completion machinery.
Did you already do that?
-- 
Thien-Thi Nguyen ..................................... GPG key: 4C807502
.                  NB: ttn at glug dot org is not me                   .
.                 (and has not been since 2007 or so)                  .
.                        ACCEPT NO SUBSTITUTES                         .
........... please send technical questions to mailing lists ...........

[-- Attachment #2: Type: application/pgp-signature, Size: 197 bytes --]

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

* Re: Error in post-command-hook (completion-in-region--postch): (wrong-type-argument stringp nil)
  2012-08-24  8:25 Error in post-command-hook (completion-in-region--postch): (wrong-type-argument stringp nil) Tassilo Horn
  2012-08-24  9:44 ` Thien-Thi Nguyen
@ 2012-08-24 15:46 ` Stefan Monnier
  2012-08-24 18:20   ` Tassilo Horn
  1 sibling, 1 reply; 9+ messages in thread
From: Stefan Monnier @ 2012-08-24 15:46 UTC (permalink / raw)
  To: emacs-devel

> (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
> 	    ;; TODO: Remove me again!
> 	    (assert (null (remove-if 'stringp completions)))
> 	    (list (car bounds) (cdr bounds) completions)))))))

The completion-in-region-mod calls to completion-at-point-functions
don't care much about the "completions" part of the triplet you return,
so the nrepl-send-string* are a complete waste.
Same for potentially other cases such as when auto-complete calls
completion-at-point-functions to try and decide whether or not there's
potentially something to complete at point.

IOW, nrepl-complete-at-point should return something more like
(guaranteed 100% untested):

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


-- Stefan



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

* Re: Error in post-command-hook (completion-in-region--postch): (wrong-type-argument stringp nil)
  2012-08-24 13:07     ` Thien-Thi Nguyen
@ 2012-08-24 16:23       ` Tassilo Horn
  2012-08-24 16:58         ` Thien-Thi Nguyen
  0 siblings, 1 reply; 9+ messages in thread
From: Tassilo Horn @ 2012-08-24 16:23 UTC (permalink / raw)
  To: Thien-Thi Nguyen; +Cc: emacs-devel

Thien-Thi Nguyen <ttn@gnuvola.org> writes:

> Sorry, i was not clear.  I would use ‘message’ in several places, each
> w/ a unique format string (to avoid Emacs combining them in
> *Messages*), to trace the execution path.

Argh, I did that now and it revealed that my completion function got
called after a successfull completion once again, and then the
(read-from-string ...) read `nil' (what the nREPL server responds if
there are no possible completions).

Thanks a ton for the hints!

Bye,
Tassilo



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

* Re: Error in post-command-hook (completion-in-region--postch): (wrong-type-argument stringp nil)
  2012-08-24 16:23       ` Tassilo Horn
@ 2012-08-24 16:58         ` Thien-Thi Nguyen
  2012-08-24 18:12           ` Tassilo Horn
  0 siblings, 1 reply; 9+ messages in thread
From: Thien-Thi Nguyen @ 2012-08-24 16:58 UTC (permalink / raw)
  To: emacs-devel

[-- Attachment #1: Type: text/plain, Size: 830 bytes --]

() Tassilo Horn <tsdh@gnu.org>
() Fri, 24 Aug 2012 18:23:06 +0200

   Argh, I did that now and it revealed that my completion function got
   called after a successfull completion once again, and then the
   (read-from-string ...) read `nil' (what the nREPL server responds if
   there are no possible completions).

Is that supposed to happen (being calling twice)?

   Thanks a ton for the hints!

Behold the power of procrastination!  :-D
-- 
Thien-Thi Nguyen ..................................... GPG key: 4C807502
.                  NB: ttn at glug dot org is not me                   .
.                 (and has not been since 2007 or so)                  .
.                        ACCEPT NO SUBSTITUTES                         .
........... please send technical questions to mailing lists ...........

[-- Attachment #2: Type: application/pgp-signature, Size: 197 bytes --]

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

* Re: Error in post-command-hook (completion-in-region--postch): (wrong-type-argument stringp nil)
  2012-08-24 16:58         ` Thien-Thi Nguyen
@ 2012-08-24 18:12           ` Tassilo Horn
  0 siblings, 0 replies; 9+ messages in thread
From: Tassilo Horn @ 2012-08-24 18:12 UTC (permalink / raw)
  To: Thien-Thi Nguyen; +Cc: emacs-devel

Thien-Thi Nguyen <ttn@gnuvola.org> writes:

>    Argh, I did that now and it revealed that my completion function got
>    called after a successfull completion once again, and then the
>    (read-from-string ...) read `nil' (what the nREPL server responds if
>    there are no possible completions).
>
> Is that supposed to happen (being calling twice)?

Yes, the completion at point stuff figures out when to delete the
*Completions* window that way.

Bye,
Tassilo



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

* Re: Error in post-command-hook (completion-in-region--postch): (wrong-type-argument stringp nil)
  2012-08-24 15:46 ` Stefan Monnier
@ 2012-08-24 18:20   ` Tassilo Horn
  0 siblings, 0 replies; 9+ messages in thread
From: Tassilo Horn @ 2012-08-24 18:20 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: emacs-devel

Stefan Monnier <monnier@iro.umontreal.ca> writes:

> The completion-in-region-mod calls to completion-at-point-functions
> don't care much about the "completions" part of the triplet you
> return, so the nrepl-send-string* are a complete waste.  Same for
> potentially other cases such as when auto-complete calls
> completion-at-point-functions to try and decide whether or not there's
> potentially something to complete at point.

Oh, (info "(elisp)Completion in Buffers") doesn't make that clear.

> IOW, nrepl-complete-at-point should return something more like
> (guaranteed 100% untested):

Except that you've copied my original error, the function works like a
charm. :-)

Thanks,
Tassilo



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

end of thread, other threads:[~2012-08-24 18:20 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-08-24  8:25 Error in post-command-hook (completion-in-region--postch): (wrong-type-argument stringp nil) Tassilo Horn
2012-08-24  9:44 ` Thien-Thi Nguyen
2012-08-24 11:23   ` Tassilo Horn
2012-08-24 13:07     ` Thien-Thi Nguyen
2012-08-24 16:23       ` Tassilo Horn
2012-08-24 16:58         ` Thien-Thi Nguyen
2012-08-24 18:12           ` Tassilo Horn
2012-08-24 15:46 ` Stefan Monnier
2012-08-24 18:20   ` Tassilo Horn

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