12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697 |
- ;;; Code:
- (defvar he-search-loc-backward (make-marker))
- (defvar he-search-loc-forward (make-marker))
- ;; Functions
- (defun distopico:try-expand-line-closest-first (old)
- "Try to complete the current line to an entire line in the buffer.
- 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.
- from: https://gist.github.com/magnars/4060654"
- (let ((expansion ())
- (strip-prompt (and (get-buffer-process (current-buffer))
- comint-use-prompt-regexp
- comint-prompt-regexp)))
- (unless old
- (he-init-string (he-line-beg strip-prompt) (point))
- (set-marker he-search-loc-backward he-string-beg)
- (set-marker he-search-loc-forward he-string-end))
- (if (not (equal he-search-string ""))
- (save-excursion
- (save-restriction
- (if hippie-expand-no-restriction
- (widen))
- (let (forward-point
- backward-point
- forward-distance
- backward-distance
- forward-expansion
- backward-expansion
- chosen)
- ;; search backward
- (goto-char he-search-loc-backward)
- (setq expansion (he-line-search he-search-string
- strip-prompt t))
- (when expansion
- (setq backward-expansion expansion)
- (setq backward-point (point))
- (setq backward-distance (- he-string-beg backward-point)))
- ;; search forward
- (goto-char he-search-loc-forward)
- (setq expansion (he-line-search he-search-string
- strip-prompt nil))
- (when expansion
- (setq forward-expansion expansion)
- (setq forward-point (point))
- (setq forward-distance (- forward-point he-string-beg)))
- ;; choose depending on distance
- (setq chosen (cond
- ((and forward-point backward-point)
- (if (< forward-distance backward-distance) :forward :backward))
- (forward-point :forward)
- (backward-point :backward)))
- (when (equal chosen :forward)
- (setq expansion forward-expansion)
- (set-marker he-search-loc-forward forward-point))
- (when (equal chosen :backward)
- (setq expansion backward-expansion)
- (set-marker he-search-loc-backward backward-point))
- ))))
- (if (not expansion)
- (progn
- (if old (he-reset-string))
- ())
- (progn
- (he-substitute-string expansion t)
- t))))
- (defun distopico:hippie-expand-lines ()
- "Create own function to expand lines."
- (interactive)
- (let ((hippie-expand-try-functions-list '(try-expand-line-closest-first
- try-expand-line-all-buffers)))
- (end-of-line)
- (hippie-expand nil)))
- (defun distopico:hippie-expand-no-case-fold ()
- "Don't case-fold when expanding with `hippe-mode'."
- (interactive)
- (let ((case-fold-search nil))
- (hippie-expand nil)))
- (provide 'conf-hippie)
- ;;; conf-hippie.el ends here
|