Skip to content

Instantly share code, notes, and snippets.

@twlz0ne
Last active December 30, 2017 18:43
Show Gist options
  • Save twlz0ne/9eb9672b10c469230dd85aa987f3d565 to your computer and use it in GitHub Desktop.
Save twlz0ne/9eb9672b10c469230dd85aa987f3d565 to your computer and use it in GitHub Desktop.
Test ivy-read
;;; Usage: /path/to/emacs -nw -Q -l /path/to/test-ivy-read.el
(toggle-debug-on-error)
(global-set-key (kbd "C-h") 'delete-backward-char)
(global-set-key (kbd "M-h") 'backward-kill-word)
(global-set-key (kbd "<f1>") 'help-command)
(define-key isearch-mode-map "\C-h" 'isearch-delete-char)
;; ------------------------------------------------------------------
(setq package-user-dir
(concat
user-emacs-directory
(format "elpa--%s/%s" (file-name-base load-file-name) emacs-version)))
(unless (load (concat user-emacs-directory "elpa.el") t)
(setq package-archives
'(("gnu" . "https://elpa.gnu.org/packages/")
("melpa" . "https://melpa.org/packages/"))))
(package-initialize)
(defun require-packages (&rest packages)
(dolist (pkg packages)
(unless (package-installed-p pkg)
(package-refresh-contents)
(package-install pkg))
(require pkg)))
(require-packages
'ivy
'counsel
)
;; ------------------------------------------------------------------
(defvar ivy-expr nil
"Holds a test expression to evaluate with `ivy-eval'.")
(defvar ivy-result nil
"Holds the eval result of `ivy-expr' by `ivy-eval'.")
(defun ivy-eval ()
"Evaluate `ivy-expr'."
(interactive)
(setq ivy-result (eval ivy-expr)))
(global-set-key (kbd "C-c e") 'ivy-eval)
(defun ivy-with (expr keys)
"Evaluate EXPR followed by KEYS."
(let ((ivy-expr expr))
(execute-kbd-macro
(vconcat (kbd "C-c e")
(kbd keys)))
ivy-result))
(add-hook 'after-init-hook
(lambda ()
(when (string= system-type "darwin")
(setq dired-use-ls-dired nil))
(message "---------- test ----------")
;; (message "[result]: %s" (ivy-with '(ivy-read "test: " '("case" "Case")) "ca TAB C-m"))
;; (message "[result]: %s" (ivy-with '(counsel-find-file "~/") "C-m"))
(dotimes (i 10)
(let ((begin-time (current-time)))
(ivy-with '(counsel-find-file "/usr/bin/") "C-m")
(message "[%d/10] %f" i (- (float-time (current-time)) (float-time begin-time)))))
(switch-to-buffer "*Messages*")
))
(run-hooks 'after-init-hook)
;;; test-ivy-read.el ends here
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment