+ (if hippie-expand-dabbrev-skip-space
+ (skip-syntax-backward ". "))
+ (if (= (skip-syntax-backward (if hippie-expand-dabbrev-as-symbol
+ "w_" "w"))
+ 0)
+ op
+ (point)))))
+
+(defun try-expand-dabbrev-from-kill (old)
+ "Try to expand word \"dynamically\", searching the kill ring.
+The argument OLD has to be nil the first call of this function, and t
+for subsequent calls (for further possible completions of the same
+string). It returns t if a new completion is found, nil otherwise."
+ (let ((expansion ()))
+ (if (not old)
+ (progn
+ (he-init-string (he-dabbrev-beg) (point))
+ (setq he-expand-list
+ (if (not (equal he-search-string ""))
+ kill-ring))
+ (setq he-search-loc2 0)))
+ (if (not (equal he-search-string ""))
+ (setq expansion (he-dabbrev-kill-search he-search-string)))
+ (if (not expansion)
+ (progn
+ (if old (he-reset-string))
+ ())
+ (progn
+ (he-substitute-string expansion t)
+ t))))
+
+(defun he-dabbrev-kill-search (pattern)
+ (let ((result ())
+ (regpat (cond ((not hippie-expand-dabbrev-as-symbol)
+ (concat "\\<" (regexp-quote pattern) "\\sw+"))
+ ((eq (char-syntax (aref pattern 0)) ?_)
+ (concat (regexp-quote pattern) "\\(\\sw\\|\\s_\\)+"))
+ (t
+ (concat "\\<" (regexp-quote pattern)
+ "\\(\\sw\\|\\s_\\)+"))))
+ (killstr (car he-expand-list)))
+ (while (and (not result)
+ he-expand-list)
+ (while (and (not result)
+ (string-match regpat killstr he-search-loc2))
+ (setq result (substring killstr (match-beginning 0) (match-end 0)))
+ (set-text-properties 0 (length result) () result)
+ (setq he-search-loc2 (1+ (match-beginning 0)))
+ (if (or (and hippie-expand-dabbrev-as-symbol
+ (> (match-beginning 0) 0)
+ (memq (char-syntax (aref killstr (1- (match-beginning 0))))
+ '(?_ ?w)))
+ (he-string-member result he-tried-table t))
+ (setq result nil))) ; ignore if bad prefix or already in table
+ (if (and (not result)
+ he-expand-list)
+ (progn
+ (setq he-expand-list (cdr he-expand-list))
+ (setq killstr (car he-expand-list))
+ (setq he-search-loc2 0))))
+ result))
+
+(defun try-expand-whole-kill (old)
+ "Try to complete text with something from the kill ring.
+The argument OLD has to be nil the first call of this function, and t
+for subsequent calls (for further possible completions of the same
+string). It returns t if a new completion is found, nil otherwise."
+ (let ((expansion ()))
+ (if (not old)
+ (progn
+ (he-init-string (he-kill-beg) (point))
+ (if (not (he-string-member he-search-string he-tried-table))
+ (setq he-tried-table (cons he-search-string he-tried-table)))
+ (setq he-expand-list
+ (if (not (equal he-search-string ""))
+ kill-ring))
+ (setq he-search-loc2 ())))
+ (if (not (equal he-search-string ""))
+ (setq expansion (he-whole-kill-search he-search-string)))
+ (if (not expansion)
+ (progn
+ (if old (he-reset-string))
+ ())
+ (progn
+ (he-substitute-string expansion)
+ t))))
+
+(defun he-whole-kill-search (str)
+ (let ((case-fold-search ())
+ (result ())
+ (str (regexp-quote str))
+ (killstr (car he-expand-list))
+ (pos -1))
+ (while (and (not result)
+ he-expand-list)
+ (if (not he-search-loc2)
+ (while (setq pos (string-match str killstr (1+ pos)))
+ (setq he-search-loc2 (cons pos he-search-loc2))))
+ (while (and (not result)
+ he-search-loc2)
+ (setq pos (car he-search-loc2))
+ (setq he-search-loc2 (cdr he-search-loc2))
+ (save-excursion
+ (goto-char he-string-beg)
+ (if (and (>= (- (point) pos) (point-min)) ; avoid some string GC
+ (eq (char-after (- (point) pos)) (aref killstr 0))
+ (search-backward (substring killstr 0 pos)
+ (- (point) pos) t))
+ (progn
+ (setq result (substring killstr pos))
+ (set-text-properties 0 (length result) () result))))
+ (if (and result
+ (he-string-member result he-tried-table))
+ (setq result nil))) ; ignore if already in table
+ (if (and (not result)
+ he-expand-list)
+ (progn
+ (setq he-expand-list (cdr he-expand-list))
+ (setq killstr (car he-expand-list))
+ (setq pos -1))))
+ result))
+
+(defun he-kill-beg ()
+ (let ((op (point)))
+ (save-excursion
+ (skip-syntax-backward "^w_")
+ (if (= (skip-syntax-backward "w_") 0)
+ op
+ (point)))))
+
+
+(provide 'hippie-exp)