Emacs Lisp and Non-Deterministic Regular Expressions

I've been spending too much time lately debugging some of the auto-complete features in Emacs, this feature seems non-deterministic and left me completely confused.

 (re-search-backward "\\(\\sw\\|\\s_\\|\\s\\.\\|\\s\\\\|[#@|]\\)\\=")

The command is called in a while loop, looking back from the current point to find the full "word" that should be autocomplete. For reference, the actual code .

A bit of background and my research

I am trying to configure autocomplete for Javascript using slime to connect to a Node.js server.

Autocomplete inside Slime REPL connected to Node.js server, excellent,

enter image description here

js2-mode, Slime, . , .

enter image description here

Slime slime-begin-of-symbol.

, fs.ch, fs , h.

slime repl , fs.ch.

js2-mode ch.

eval ing (re-search-backward "\\(\\sw\\|\\s_\\|\\s\\.\\|\\s\\\\|[#@|]\\)\\=") . , .

  • fs.ch c.
  • slime repl fs.ch f.
  • js2-mode fs.ch c.
  • emacs- lisp - fs.ch f.

,

, - , unsets var, , - - .

emacs c, , .

+4
2

"" , , auto complete ac-sources.

elisp, , , , , .

:

\\(\\sw\\|\\s_\\|\\s\\.\\|\\s\\\\|[#@|]\\)\\=

\\(\\sw\\|\\s_\\|\\s.\\|\\s\\\\|[#@|]\\)\\=

( \\s\\.\\ \\s.\\).

init.el. (, , , , elisp).

(defun js-slime-beginning-of-symbol ()
  "Move to the beginning of the CL-style symbol at point."
  (while (re-search-backward "\\(\\sw\\|\\s_\\|\\s.\\|\\s\\\\|[#@|]\\)\\="
                             (when (> (point) 2000) (- (point) 2000))
                             t))
  (re-search-forward "\\=#[-+.<|]" nil t)
  (when (and (looking-at "@") (eq (char-before) ?\,))
    (forward-char)))

(defun js-slime-symbol-start-pos ()
  "Return the starting position of the symbol under point.
The result is unspecified if there isn't a symbol under the point."
  (save-excursion (js-slime-beginning-of-symbol) (point)))

(defvar ac-js-source-slime-simple
  '((init . ac-slime-init)
    (candidates . ac-source-slime-simple-candidates)
    (candidate-face . ac-slime-menu-face)
    (selection-face . ac-slime-selection-face)
    (prefix . js-slime-symbol-start-pos)
    (symbol . "l")
    (document . ac-slime-documentation)
    (match . ac-source-slime-case-correcting-completions))
  "Source for slime completion.")

(defun set-up-slime-js-ac (&optional fuzzy)
  "Add an optionally-fuzzy slime completion source to `ac-sources'."
  (interactive)
  (add-to-list 'ac-sources ac-js-source-slime-simple))

regex. .

Emacs regexes , , , . , lisp, js, - . lisp '.' , js2- '.' .

, - . js2-. . (modify-syntax-entry ?. "w"). , , , - .

, #emacs, , regex.

0

\\s\\. \\s. .

+1

All Articles