Subject: Re: bug#17529: 24.3; Error in hippie-expand

From: Nicolas Richard <[email-masked]>
Date: Mon, 19 May 2014 23:01:10 +0200

Glenn Morris <[email-masked]> writes:
> Can you do:
> M-x toggle-debug-no-error
> repeat the problem, and send the backtrace?

More details should come soon from the OP, but we managed to debug this
over IRC so I post the outcome :

First here's the backtrace :

Debugger entered--Lisp error: (wrong-type-argument integer-or-marker-p nil)
  buffer-substring-no-properties(nil 9745)
  he-init-string(nil 9745)
  try-expand-line(nil)
  apply(try-expand-line nil)
  hippie-expand(nil)
  call-interactively(hippie-expand record nil)
  command-execute(hippie-expand record)
  execute-extended-command(nil "hippie-expand")
  call-interactively(execute-extended-command nil nil)

This means that (he-line-beg strip-prompt) (that is called within
try-expand-line) returned nil. The reason is that it tries to collect
the 2nd group of a regexp that is not fully under control, namely
comint-prompt-regexp. In ESS, that regexp contains grouping constructs.

To avoid the problem, one solution is to replace "2" by "the last
group". The following patch thus fixes the problem for me... but (1- (/
(length (match-data)) 2)) is a bit cryptic.

--- /usr/local/share/emacs/24.3.91/lisp/hippie-exp.el.gz
+++ #<buffer hippie-exp.el.gz>
@@ -710,7 +710,7 @@
   (save-excursion
     (if (re-search-backward (he-line-search-regexp "" strip-prompt)
 			    (line-beginning-position) t)
-	(match-beginning 2)
+	(match-beginning (1- (/ (length (match-data)) 2)))
       (point))))
 
 (defun he-line-search-regexp (pat strip-prompt)

-- 
Nico.