Function: try-expand-dabbrev-visible

try-expand-dabbrev-visible is a byte-compiled function defined in hippie-exp.el.gz.

Signature

(try-expand-dabbrev-visible OLD)

Documentation

Try to expand word "dynamically", searching visible window parts.

The argument OLD has to be nil the first call of this function, and t for subsequent calls (for further possible expansions of the same string). It returns t if a new expansion is found, nil otherwise.

Source Code

;; Defined in /usr/src/emacs/lisp/hippie-exp.el.gz
;; Thanks go to Jeff Dairiki <dairiki@faraday.apl.washington.edu> who
;; suggested this one.
(defun try-expand-dabbrev-visible (old)
  "Try to expand word \"dynamically\", searching visible window parts.
The argument OLD has to be nil the first call of this function, and t
for subsequent calls (for further possible expansions of the same
string).  It returns t if a new expansion is found, nil otherwise."
  (let ((expansion ())
	(flag (if (frame-visible-p (window-frame))
		  'visible t)))
    (unless old
      (he-init-string (he-dabbrev-beg) (point))
      (setq he-search-window (selected-window))
      (set-marker he-search-loc
                  (window-start he-search-window)
                  (window-buffer he-search-window)))

    (while (and (not (equal he-search-string ""))
                (marker-position he-search-loc)
                (not expansion))
      (with-current-buffer (marker-buffer he-search-loc)
        (save-excursion
          (goto-char he-search-loc)
          (setq expansion (he-dabbrev-search he-search-string ()
                                             (window-end he-search-window)))
          (if (and expansion
                   (eq (marker-buffer he-string-beg) (current-buffer))
                   (eq (marker-position he-string-beg) (match-beginning 0)))
              (setq expansion
                    (he-dabbrev-search he-search-string ()
                                       (window-end he-search-window))))
          (set-marker he-search-loc (point) (current-buffer))))
      (unless expansion
        (setq he-search-window (next-window he-search-window nil flag))
        (if (eq he-search-window (selected-window))
            (set-marker he-search-loc nil)
          (set-marker he-search-loc (window-start he-search-window)
                      (window-buffer he-search-window)))))

    (if (not expansion)
	(progn
	  (if old (he-reset-string))
	  ())
	(progn
	  (he-substitute-string expansion t)
	  t))))