Re: Fedora Core 3: File mode specification error

Brett Presnell <[email protected]>
Newsgroups gmane.emacs.auc-tex
Message-ID <[email protected]>
David Kastrup <[email protected]> writes:

> [email protected] writes:
>
> Can you check your definition of regexp-opt-group?  And maybe do a
> edebug-defun on its definition, and then see what happens when calling
> (regexp-opt nil)
> ?

Ok, I did all this, hopefully correctly.

Here's the definition I get for regexp-opt-group:

(defun regexp-opt-group (strings &optional paren lax)
  ;;
  ;; Return a regexp to match a string in STRINGS.
  ;; If PAREN non-nil, output regexp parentheses around returned regexp.
  ;; If LAX non-nil, don't output parentheses if it doesn't require them.
  ;; Merges keywords to avoid backtracking in Emacs' regexp matcher.
  ;;
  ;; The basic idea is to find the shortest common prefix, remove it and
  ;; recurse.  If there is no prefix, we divide the list into two so that (at
  ;; least) one half will have at least a one-character common prefix.
  ;;
  ;; Also we delay the addition of grouping parenthesis as long as possible
  ;; until we're sure we need them, and try to remove one-character sequences
  ;; so we can use character sets rather than grouping parenthesis.
  ;;
  (let* ((open-group (if paren "\\(" ""))
	 (close-group (if paren "\\)" ""))
	 (open-charset (if lax "" open-group))
	 (close-charset (if lax "" close-group)))
    (cond
     ;;
     ;; If there is only one string, just return it.
     ((= (length strings) 1)
      (if (= (length (car strings)) 1)
	  (concat open-charset (regexp-quote (car strings)) close-charset)
	(concat open-group (regexp-quote (car strings)) close-group)))
     ;;
     ;; If there is an empty string, remove it and recurse on the rest.
     ((= (length (car strings)) 0)
      (concat open-charset
	      (regexp-opt-group (cdr strings) t t) "?"
	      close-charset))
     ;;
     ;; If all are one-character strings, just return a character set.
     ((= (length strings) (apply '+ (mapcar 'length strings)))
      (concat open-charset
	      (regexp-opt-charset strings)
	      close-charset))
     ;;
     ;; We have a list of different length strings.
     (t
      (let ((prefix (try-completion "" (mapcar 'list strings)))
	    (letters (let ((completion-regexp-list '("^.$")))
		       (all-completions "" (mapcar 'list strings)))))
	(cond
	 ;;
	 ;; If there is a common prefix, remove it and recurse on the suffixes.
	 ((> (length prefix) 0)
	  (let* ((length (length prefix))
		 (suffixes (mapcar (lambda (s) (substring s length)) strings)))
	    (concat open-group
		    (regexp-quote prefix) (regexp-opt-group suffixes t t)
		    close-group)))
	 ;;
	 ;; If there are several one-character strings, remove them and recurse
	 ;; on the rest (first so the final regexp finds the longest match).
	 ((> (length letters) 1)
	  (let ((rest (let ((completion-regexp-list '("^..+$")))
			(all-completions "" (mapcar 'list strings)))))
	    (concat open-group
		    (regexp-opt-group rest) "\\|" (regexp-opt-charset letters)
		    close-group)))
	 ;;
	 ;; Otherwise, divide the list into those that start with a particular
	 ;; letter and those that do not, and recurse on them.
	 (t
	  (let* ((char (substring (car strings) 0 1))
		 (half1 (all-completions char (mapcar 'list strings)))
		 (half2 (nthcdr (length half1) strings)))
	    (concat open-group
		    (regexp-opt-group half1) "\\|" (regexp-opt-group half2)
		    close-group)))))))))

------------------------------------------------------------

When I do "M-x edebug-defun" on regexp-opt-group and step through the
function I just cycle through these lines over and over

  (let* ((open-group (if paren "\\(" ""))
	 (close-group (if paren "\\)" ""))
	 (open-charset (if lax "" open-group))
	 (close-charset (if lax "" close-group)))
    (cond
     ;;
     ;; If there is only one string, just return it.
     ((= (length strings) 1)
      (if (= (length (car strings)) 1)
	  (concat open-charset (regexp-quote (car strings)) close-charset)
	(concat open-group (regexp-quote (car strings)) close-group)))
     ;;
     ;; If there is an empty string, remove it and recurse on the rest.
     ((= (length (car strings)) 0)
      (concat open-charset
	      (regexp-opt-group (cdr strings) t t) "?"

(it never quite gets to the end of that last line before it jumps to the 
first line again).

------------------------------------------------------------

BTW, I noticed that when I try to run edebug-defun on
regexp-opt-charset I get the following error:

edebug-syntax-error: Invalid read syntax: "Head of list form must be a symbol or lambda expression."

I started with the cursor position exactly at the start of the defun, 
just as for regexp-opt-group.  Maybe this isn't supposed to work, but
I thought that I would mention it.

------------------------------------------------------------

Here is the result of 

M-x eval-expression<Return>regexp-opt nil<Return>

i.e., (eval-expression (quote regexp-opt) nil):

Debugger entered--Lisp error: (void-variable regexp-opt)
  eval(regexp-opt)
  eval-expression(regexp-opt nil)
  eval((eval-expression (quote regexp-opt) nil))
  repeat-complex-command(1)
  call-interactively(repeat-complex-command)
  recursive-edit()
  byte-code("Æ!ˆÃ‡ ˆÃˆ	!ˆ\nƒ?Éed\"Vƒ4ebˆÃŠÂÂ¥yˆ`dbˆÃŠÂÂ¥Zyˆ\f`|ˆ)ËcˆebˆÃŒÍ !ˆÃŽ ˆ	@Ï=ƒKÐÑÒ\"ˆÃ“ ˆÃŒÔ!ˆÃ’ÕÃ’ÌÔ!ˆÂŠÖ ˆ,Õ‡" [debugger-buffer debugger-args noninteractive debugger-batch-max-lines middlestart buffer-read-only pop-to-buffer debugger-mode debugger-setup-buffer count-lines 2 "...\n" message buffer-string kill-emacs debug backtrace-debug 3 t debugger-reenable "" nil recursive-edit standard-output inhibit-trace] 3)
  debug(error (void-variable regexp-opt))
  eval(regexp-opt)
  eval-expression(regexp-opt nil)
* call-interactively(eval-expression)
  execute-extended-command(nil)
  call-interactively(execute-extended-command)
  recursive-edit()
  byte-code("Æ!ˆÃ‡ ˆÃˆ	!ˆ\nƒ?Éed\"Vƒ4ebˆÃŠÂÂ¥yˆ`dbˆÃŠÂÂ¥Zyˆ\f`|ˆ)ËcˆebˆÃŒÍ !ˆÃŽ ˆ	@Ï=ƒKÐÑÒ\"ˆÃ“ ˆÃŒÔ!ˆÃ’ÕÃ’ÌÔ!ˆÂŠÖ ˆ,Õ‡" [debugger-buffer debugger-args noninteractive debugger-batch-max-lines middlestart buffer-read-only pop-to-buffer debugger-mode debugger-setup-buffer count-lines 2 "...\n" message buffer-string kill-emacs debug backtrace-debug 3 t debugger-reenable "" nil recursive-edit standard-output inhibit-trace] 3)
  debug(error (error "Variable binding depth exceeds max-specpdl-size"))
  regexp-opt-group(nil t t)
  regexp-opt-group(nil t t)
  regexp-opt-group(nil t t)
  regexp-opt-group(nil t t)
  regexp-opt-group(nil t t)
  regexp-opt-group(nil t t)
  regexp-opt-group(nil t t)
  regexp-opt-group(nil t t)
  regexp-opt-group(nil t t)
  regexp-opt-group(nil t t)
  regexp-opt-group(nil t t)
  regexp-opt-group(nil t t)
  regexp-opt-group(nil t t)
  regexp-opt-group(nil t t)
  regexp-opt-group(nil t t)
  regexp-opt-group(nil t t)
  regexp-opt-group(nil t t)
  regexp-opt-group(nil t t)
  regexp-opt-group(nil t t)
  regexp-opt-group(nil t t)
  regexp-opt-group(nil t t)
  regexp-opt-group(nil t t)
  regexp-opt-group(nil t t)
  regexp-opt-group(nil t t)
  regexp-opt-group(nil t t)
  regexp-opt-group(nil t t)
  regexp-opt-group(nil t t)
  regexp-opt-group(nil t t)
  regexp-opt-group(nil t t)
  regexp-opt-group(nil t t)
  regexp-opt-group(nil t t)
  regexp-opt-group(nil t t)
  regexp-opt-group(nil t t)
  regexp-opt-group(nil t t)
  regexp-opt-group(nil t t)
  regexp-opt-group(nil t t)
  regexp-opt-group(nil t t)
  regexp-opt-group(nil t t)
  regexp-opt-group(nil t t)
  regexp-opt-group(nil t t)
  regexp-opt-group(nil t t)
  regexp-opt-group(nil t t)
  regexp-opt-group(nil t t)
  regexp-opt-group(nil t t)
  regexp-opt-group(nil t t)
  regexp-opt-group(nil t t)
  regexp-opt-group(nil t t)
  regexp-opt-group(nil t t)
  regexp-opt-group(nil t t)
  regexp-opt-group(nil t t)
  regexp-opt-group(nil t t)
  regexp-opt-group(nil t t)
  regexp-opt-group(nil t t)
  regexp-opt-group(nil t t)
  regexp-opt-group(nil t t)
  regexp-opt-group(nil t t)
  regexp-opt-group(nil t t)
  regexp-opt-group(nil t t)
  regexp-opt-group(nil t t)
  regexp-opt-group(nil t t)
  regexp-opt-group(nil t t)
  regexp-opt-group(nil t t)
  regexp-opt-group(nil t t)
  regexp-opt-group(nil t t)
  regexp-opt-group(nil t t)
  regexp-opt-group(nil t t)
  regexp-opt-group(nil t t)
  regexp-opt-group(nil t t)
  regexp-opt-group(nil t t)
  regexp-opt-group(nil t t)
  regexp-opt-group(nil t t)
  regexp-opt-group(nil t t)
  regexp-opt-group(nil t t)
  regexp-opt-group(nil t t)
  regexp-opt-group(nil t t)
  regexp-opt-group(nil t t)
  regexp-opt-group(nil t t)
  regexp-opt-group(nil t t)
  regexp-opt-group(nil t t)
  regexp-opt-group(nil t t)
  regexp-opt-group(nil t t)
  regexp-opt-group(nil t t)
  regexp-opt-group(nil t t)
  regexp-opt-group(nil t t)
  regexp-opt-group(nil t t)
  regexp-opt-group(nil t t)
  regexp-opt-group(nil t t)
  regexp-opt-group(nil t t)
  regexp-opt-group(nil t t)
  regexp-opt-group(nil t t)
  regexp-opt-group(nil t t)
  regexp-opt-group(nil t t)
  regexp-opt-group(nil t t)
  regexp-opt-group(nil t t)
  regexp-opt-group(nil t t)
  regexp-opt-group(nil t t)
  regexp-opt-group(nil t t)
  regexp-opt-group(nil nil)
  regexp-opt(nil)
  eval((regexp-opt nil))
  eval-expression((regexp-opt nil) nil)
* call-interactively(eval-expression)
  execute-extended-command(nil)
  call-interactively(execute-extended-command)

------------------------------------------------------------
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.