Skip to content

Instantly share code, notes, and snippets.

@hchbaw
Created June 11, 2009 16:08
Show Gist options
  • Save hchbaw/128017 to your computer and use it in GitHub Desktop.
Save hchbaw/128017 to your computer and use it in GitHub Desktop.
(defvar anything-show-completion-height-percent 50
"Maximum percentage of display height that will be preserved when this
`anything-display-function' splits the window.")
(defvar asc-scroll 0
"Hold the state of the scrolled-upped value.")
(defun asc-scroll-display-function (buf)
(save-excursion
(setq asc-scroll 0)
(asc-scroll-up-maybe)
(let ((split-window-keep-point)
(hsize (1+ (count-screen-lines (window-start) (point)))))
(split-window-vertically (max hsize window-min-height))
(other-window 1)
(switch-to-buffer buf))))
(defun asc-scroll-up-maybe ()
(let* ((lc (count-screen-lines (window-start) (point)))
(v (truncate (/ (* 100 lc) (window-height)))))
(when (< anything-show-completion-height-percent v)
(let ((up (- lc
(truncate
(* (window-height)
(/ anything-show-completion-height-percent 100.0))))))
(setq asc-scroll up)
(scroll-up up)))))
;; Entry point for an experiment.
(defun use-anything-show-completeion* (function prefix-length-sexp display-function &rest body)
(eval
`(progn
(ad-disable-advice ',function
'around
'anything-show-completion)
(ad-deactivate ',function)
(defadvice ,function (around anything-show-completion activate)
(anything-show-completion-install ',prefix-length-sexp)
(let ((anything-display-function ',display-function))
ad-do-it))
,@body)))
(apply 'use-anything-show-completeion*
'(anything-complete
(length anything-complete-target)
asc-scroll-display-function
(defadvice anything-complete (after scroll-up activate)
(when (not (zerop asc-scroll))
(scroll-up asc-scroll)))))
;; For anything-zsh-screen :)
(defun asc-scroll-up0 (up)
(cond ((eq major-mode 'term-mode)
(term-send-raw-string "\033q")
(term-send-raw-string (format " print -n \"\\033[%dA\"\n"
(1+ up))))
(t (scroll-up up))))
(defvar asc-scroll-up-function 'asc-scroll-up0)
(defun asc-scroll-up (up)
(funcall asc-scroll-up-function up))
(apply 'use-anything-show-completeion*
'(anything-zsh-screen-complete
(anything-zsh-screen-get-prefix-length)
asc-scroll-display-function
(defadvice anything-zsh-screen-complete (after scroll-up activate)
(when (not (zerop asc-scroll))
(asc-scroll-up asc-scroll)))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment