Function: next-cdabbrev
next-cdabbrev is a byte-compiled function defined in completion.el.gz.
Signature
(next-cdabbrev)
Documentation
Return the next possible cdabbrev expansion or nil if there isn't one.
reset-cdabbrev must've been called already.
This is sensitive to case-fold-search.
Source Code
;; Defined in /usr/src/emacs/lisp/completion.el.gz
(defun next-cdabbrev ()
"Return the next possible cdabbrev expansion or nil if there isn't one.
`reset-cdabbrev' must've been called already.
This is sensitive to `case-fold-search'."
;; note that case-fold-search affects the behavior of this function
;; Bug: won't pick up an expansion that starts at the top of buffer
(if cdabbrev-current-window
(let (saved-point
saved-syntax
(expansion nil)
downcase-expansion tried-list syntax saved-point-2)
(save-excursion
(unwind-protect
(progn
;; Switch to current completion buffer
(set-cdabbrev-buffer)
;; Save current buffer state
(setq saved-point (point)
saved-syntax (syntax-table))
;; Restore completion state
(set-syntax-table completion-syntax-table)
(goto-char cdabbrev-current-point)
;; Loop looking for completions
(while
;; This code returns t if it should loop again
(cond
(;; search for the string
(search-backward cdabbrev-abbrev-string cdabbrev-stop-point t)
;; return nil if the completion is valid
(not
(and
;; does it start with a separator char ?
(or (= (setq syntax (char-syntax (preceding-char))) ? )
(and (= syntax ?w)
;; symbol char to ignore at end. Are we at end ?
(progn
(setq saved-point-2 (point))
(forward-word-strictly -1)
(prog1
(= (char-syntax (preceding-char)) ? )
(goto-char saved-point-2)))))
;; is the symbol long enough ?
(setq expansion (symbol-under-point))
;; have we not tried this one before
(progn
;; See if we've already used it
(setq tried-list cdabbrev-completions-tried
downcase-expansion (downcase expansion))
(while (and tried-list
(not (string-equal downcase-expansion
(car tried-list))))
;; Already tried, don't choose this one
(setq tried-list (cdr tried-list)))
;; at this point tried-list will be nil if this
;; expansion has not yet been tried
(if tried-list
(setq expansion nil)
t)))))
;; search failed
(cdabbrev-wrapped-p
;; If already wrapped, then we've failed completely
nil)
(t
;; need to wrap
(goto-char (setq cdabbrev-current-point
(if completion-search-distance
(min (point-max) (+ cdabbrev-start-point completion-search-distance))
(point-max))))
(setq cdabbrev-wrapped-p t))))
;; end of while loop
(cond (expansion
;; successful
(setq cdabbrev-completions-tried
(cons downcase-expansion cdabbrev-completions-tried)
cdabbrev-current-point (point)))))
(set-syntax-table saved-syntax)
(goto-char saved-point)))
;; If no expansion, go to next window
(cond (expansion)
(t (reset-cdabbrev-window)
(next-cdabbrev))))))