Created
October 15, 2009 17:34
-
-
Save hchbaw/211127 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;;; http://www.emacswiki.org/emacs/anything-complete.el | |
(defun* alcs-transformer-prepend-spacer+-0 | |
(candidates source &optional (prepend (lambda (cand column) | |
(concat (make-string column ? ) | |
cand)))) | |
(let ((column (with-current-buffer anything-current-buffer | |
(save-excursion | |
(backward-char (string-width anything-complete-target)) | |
(let ((col (alcs-current-physical-column))) | |
(if (< col 0) | |
;; 0 | |
(- (point) (save-excursion (forward-line 0) (point))) | |
col)))))) | |
(mapcar (lambda (cand) | |
(cons (funcall prepend cand column) | |
(or (get-text-property 0 'anything-realvalue cand) cand))) | |
candidates))) | |
(defun alcs-transformer-prepend-spacer-default (candidates source) | |
"Prepend spaces according to `current-column' for each CANDIDATES." | |
(alcs-transformer-prepend-spacer+-0 candidates source | |
(lambda (cand column) | |
(concat (make-string column ? ) | |
cand)))) | |
(require 'term) ;; term-window-width | |
(defalias 'alcs-window-width 'term-window-width) | |
;; (defun alcs-transformer-prepend-spacer+ (cs s) | |
;; (funcall (apply-partially 'alcs-transformer-prepend-spacer+-0 cs s) | |
;; (lexical-let ((ww (alcs-window-width))) | |
;; (lambda (cand column) | |
;; (let ((sw (string-width cand))) | |
;; (concat (make-string (if (< (+ column sw) ww) | |
;; column | |
;; (- column (- (+ column sw) ww))) | |
;; ? ) | |
;; cand)))))) | |
;; WIP: | |
(defun alcs-transformer-prepend-spacer+ (cs s) | |
(funcall (apply-partially 'alcs-transformer-prepend-spacer+-0 cs s) | |
(lexical-let ((ww (alcs-window-width)) | |
(sw (reduce (lambda (acc x) | |
(max acc (string-width x))) | |
cs | |
:initial-value 0))) | |
(lambda (cand column) | |
;; TODO: Too much computation. Klugdey interface anyway. | |
(concat (make-string (if (< (+ column sw) ww) | |
column | |
(- column (- (+ column sw) ww))) | |
? ) | |
cand))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment