Mercurial > hg > xemacs-beta
diff lisp/packages/completion.el @ 88:821dec489c24 r20-0
Import from CVS: tag r20-0
author | cvs |
---|---|
date | Mon, 13 Aug 2007 09:09:59 +0200 |
parents | 131b0175ea99 |
children | 34a5b81f86ba |
line wrap: on
line diff
--- a/lisp/packages/completion.el Mon Aug 13 09:09:05 2007 +0200 +++ b/lisp/packages/completion.el Mon Aug 13 09:09:59 2007 +0200 @@ -622,42 +622,36 @@ "Returns the symbol that the point is currently on. But only if it is longer than `completion-min-length'." (setq cmpl-saved-syntax (syntax-table)) - ;; XEmacs change - (set-syntax-table cmpl-syntax-table) - (cond - ;; Cursor is on following-char and after preceding-char - ((memq (char-syntax (following-char)) '(?w ?_)) - (setq cmpl-saved-point (point) - cmpl-symbol-start (scan-sexps (1+ cmpl-saved-point) -1) - cmpl-symbol-end (scan-sexps cmpl-saved-point 1)) - ;; remove chars to ignore at the start - (cond ((= (char-syntax (char-after cmpl-symbol-start)) ?w) - (goto-char cmpl-symbol-start) - (forward-word 1) - (setq cmpl-symbol-start (point)) - (goto-char cmpl-saved-point) - )) - ;; remove chars to ignore at the end - (cond ((= (char-syntax (char-after (1- cmpl-symbol-end))) ?w) - (goto-char cmpl-symbol-end) - (forward-word -1) - (setq cmpl-symbol-end (point)) - (goto-char cmpl-saved-point) - )) - ;; restore state - (set-syntax-table cmpl-saved-syntax) - ;; Return completion if the length is reasonable - (if (and (<= (cmpl-read-time-eval completion-min-length) - (- cmpl-symbol-end cmpl-symbol-start)) - (<= (- cmpl-symbol-end cmpl-symbol-start) - (cmpl-read-time-eval completion-max-length))) - (buffer-substring cmpl-symbol-start cmpl-symbol-end)) - ) - (t - ;; restore table if no symbol - (set-syntax-table cmpl-saved-syntax) - nil) - )) + (unwind-protect + (progn + (set-syntax-table cmpl-syntax-table) + (cond + ;; Cursor is on following-char and after preceding-char + ((memq (char-syntax (following-char)) '(?w ?_)) + (setq cmpl-saved-point (point) + cmpl-symbol-start (scan-sexps (1+ cmpl-saved-point) -1) + cmpl-symbol-end (scan-sexps cmpl-saved-point 1)) + ;; Remove chars to ignore at the start. + (cond ((= (char-syntax (char-after cmpl-symbol-start)) ?w) + (goto-char cmpl-symbol-start) + (forward-word 1) + (setq cmpl-symbol-start (point)) + (goto-char cmpl-saved-point) + )) + ;; Remove chars to ignore at the end. + (cond ((= (char-syntax (char-after (1- cmpl-symbol-end))) ?w) + (goto-char cmpl-symbol-end) + (forward-word -1) + (setq cmpl-symbol-end (point)) + (goto-char cmpl-saved-point) + )) + ;; Return completion if the length is reasonable. + (if (and (<= (cmpl-read-time-eval completion-min-length) + (- cmpl-symbol-end cmpl-symbol-start)) + (<= (- cmpl-symbol-end cmpl-symbol-start) + (cmpl-read-time-eval completion-max-length))) + (buffer-substring cmpl-symbol-start cmpl-symbol-end))))) + (set-syntax-table cmpl-saved-syntax))) ;; tests for symbol-under-point ;; `^' indicates cursor pos. where value is returned @@ -676,58 +670,50 @@ Returns nil if there isn't one longer than `completion-min-length'." ;; This is called when a word separator is typed so it must be FAST ! (setq cmpl-saved-syntax (syntax-table)) - ;; XEmacs change - (set-syntax-table cmpl-syntax-table) - ;; Cursor is on following-char and after preceding-char - (cond ((= (setq cmpl-preceding-syntax (char-syntax (preceding-char))) ?_) - ;; No chars. to ignore at end - (setq cmpl-symbol-end (point) - cmpl-symbol-start (scan-sexps (1+ cmpl-symbol-end) -1) + (unwind-protect + (progn + (set-syntax-table cmpl-syntax-table) + ;; Cursor is on following-char and after preceding-char + (cond ((= (setq cmpl-preceding-syntax (char-syntax (preceding-char))) ?_) + ;; Number of chars to ignore at end. + (setq cmpl-symbol-end (point) + cmpl-symbol-start (scan-sexps cmpl-symbol-end -1) + ) + ;; Remove chars to ignore at the start. + (cond ((= (char-syntax (char-after cmpl-symbol-start)) ?w) + (goto-char cmpl-symbol-start) + (forward-word 1) + (setq cmpl-symbol-start (point)) + (goto-char cmpl-symbol-end) + )) + ;; Return value if long enough. + (if (>= cmpl-symbol-end + (+ cmpl-symbol-start + (cmpl-read-time-eval completion-min-length))) + (buffer-substring cmpl-symbol-start cmpl-symbol-end)) ) - ;; XEmacs change - ;; remove chars to ignore at the start - (cond ((= (char-syntax (char-after cmpl-symbol-start)) ?w) - (goto-char cmpl-symbol-start) - (forward-word 1) - (setq cmpl-symbol-start (point)) - (goto-char cmpl-symbol-end) - )) - ;; restore state - (set-syntax-table cmpl-saved-syntax) - ;; return value if long enough - (if (>= cmpl-symbol-end - (+ cmpl-symbol-start - (cmpl-read-time-eval completion-min-length))) - (buffer-substring cmpl-symbol-start cmpl-symbol-end)) - ) - ((= cmpl-preceding-syntax ?w) - ;; chars to ignore at end - (setq cmpl-saved-point (point) - cmpl-symbol-start (scan-sexps (1+ cmpl-saved-point) -1)) - ;; take off chars. from end - (forward-word -1) - (setq cmpl-symbol-end (point)) - ;; remove chars to ignore at the start - (cond ((= (char-syntax (char-after cmpl-symbol-start)) ?w) - (goto-char cmpl-symbol-start) - (forward-word 1) - (setq cmpl-symbol-start (point)) - )) - ;; restore state - (goto-char cmpl-saved-point) - (set-syntax-table cmpl-saved-syntax) - ;; Return completion if the length is reasonable - (if (and (<= (cmpl-read-time-eval completion-min-length) - (- cmpl-symbol-end cmpl-symbol-start)) - (<= (- cmpl-symbol-end cmpl-symbol-start) - (cmpl-read-time-eval completion-max-length))) - (buffer-substring cmpl-symbol-start cmpl-symbol-end)) - ) - (t - ;; restore table if no symbol - (set-syntax-table cmpl-saved-syntax) - nil) - )) + ((= cmpl-preceding-syntax ?w) + ;; chars to ignore at end + (setq cmpl-saved-point (point) + cmpl-symbol-start (scan-sexps cmpl-saved-point -1)) + ;; take off chars. from end + (forward-word -1) + (setq cmpl-symbol-end (point)) + ;; remove chars to ignore at the start + (cond ((= (char-syntax (char-after cmpl-symbol-start)) ?w) + (goto-char cmpl-symbol-start) + (forward-word 1) + (setq cmpl-symbol-start (point)) + )) + ;; Restore state. + (goto-char cmpl-saved-point) + ;; Return completion if the length is reasonable + (if (and (<= (cmpl-read-time-eval completion-min-length) + (- cmpl-symbol-end cmpl-symbol-start)) + (<= (- cmpl-symbol-end cmpl-symbol-start) + (cmpl-read-time-eval completion-max-length))) + (buffer-substring cmpl-symbol-start cmpl-symbol-end))))) + (set-syntax-table cmpl-saved-syntax))) ;; tests for symbol-before-point ;; `^' indicates cursor pos. where value is returned @@ -748,18 +734,17 @@ ;; copying all the code. ;; However, it is only used by the completion string prompter. ;; If it comes into common use, it could be rewritten. - ;; XEmacs change - (setq cmpl-saved-syntax (syntax-table)) - (set-syntax-table cmpl-syntax-table) - (cond ((memq (char-syntax (following-char)) '(?w ?_)) - (set-syntax-table cmpl-saved-syntax) + (cond ((memq (progn + (setq cmpl-saved-syntax (syntax-table)) + (unwind-protect + (progn + (set-syntax-table cmpl-syntax-table) + (char-syntax (following-char))) + (set-syntax-table cmpl-saved-syntax))) + '(?w ?_)) (symbol-under-point)) (t - ;; XEmacs change - (set-syntax-table cmpl-saved-syntax) - (symbol-before-point)) - )) - + (symbol-before-point)))) (defun symbol-before-point-for-complete () ;; "Returns a string of the symbol immediately before point @@ -767,35 +752,30 @@ ;; end chars." ;; Cursor is on following-char and after preceding-char (setq cmpl-saved-syntax (syntax-table)) - ;; XEmacs change - (set-syntax-table cmpl-syntax-table) - (cond ((memq (setq cmpl-preceding-syntax (char-syntax (preceding-char))) - '(?_ ?w)) - (setq cmpl-symbol-end (point) - cmpl-symbol-start (scan-sexps (1+ cmpl-symbol-end) -1) - ) - ;; remove chars to ignore at the start - (cond ((= (char-syntax (char-after cmpl-symbol-start)) ?w) - (goto-char cmpl-symbol-start) - (forward-word 1) - (setq cmpl-symbol-start (point)) - (goto-char cmpl-symbol-end) - )) - ;; restore state - (set-syntax-table cmpl-saved-syntax) - ;; Return completion if the length is reasonable - (if (and (<= (cmpl-read-time-eval - completion-prefix-min-length) - (- cmpl-symbol-end cmpl-symbol-start)) - (<= (- cmpl-symbol-end cmpl-symbol-start) - (cmpl-read-time-eval completion-max-length))) - (buffer-substring cmpl-symbol-start cmpl-symbol-end)) - ) - (t - ;; restore table if no symbol - (set-syntax-table cmpl-saved-syntax) - nil) - )) + (unwind-protect + (progn + (set-syntax-table cmpl-syntax-table) + (cond ((memq (setq cmpl-preceding-syntax (char-syntax (preceding-char))) + '(?_ ?w)) + (setq cmpl-symbol-end (point) + cmpl-symbol-start (scan-sexps cmpl-symbol-end -1) + ) + ;; Remove chars to ignore at the start. + (cond ((= (char-syntax (char-after cmpl-symbol-start)) ?w) + (goto-char cmpl-symbol-start) + (forward-word 1) + (setq cmpl-symbol-start (point)) + (goto-char cmpl-symbol-end) + )) + ;; Return completion if the length is reasonable. + (if (and (<= (cmpl-read-time-eval + completion-prefix-min-length) + (- cmpl-symbol-end cmpl-symbol-start)) + (<= (- cmpl-symbol-end cmpl-symbol-start) + (cmpl-read-time-eval completion-max-length))) + (buffer-substring cmpl-symbol-start cmpl-symbol-end))))) + ;; Restore syntax table. + (set-syntax-table cmpl-saved-syntax))) ;; tests for symbol-before-point-for-complete ;; `^' indicates cursor pos. where value is returned