Preamble
Christmas day in Canada. Browsed the analytics for Reading World Magazine this morning and was surprised to see more than a few views in the Emacs pages.
Wishing those of you configuring your Emacs configurations on Christmas day a Merry Christmas 🎅
Know that you are not alone.
Emacs Posting
In this post I introduced the ivy-rich code that adds additional information and functionality to the counsel package.
In today's post, you can find the ivy configuration, as well as other packages that are still handy to have installed.
Ivy is a completion package that complements the counsel package buffer functionality well.
While there are many other buffer enhancing frameworks in Emacs, the Ivy + Counsel combination is often viewed as an alternative to the Helm framework.
Flx-ido and Flx-isearch
;good for ivy
(use-package flx ;; Improves sorting for fuzzy-matched results
:after ivy
:defer t
:init
(setq ivy-flx-limit 10000))
;ido mode and supporting
(use-package flx-ido
:init
(ido-mode 1)
;(ido-everywhere 1)
(flx-ido-mode 1)
;~ tilda to go to home directory
(defun my/ido-go-straight-home ()
(interactive)
(cond
((looking-back "~/") (insert "projects/"))
((looking-back "/") (insert "~/"))
(:else (call-interactively 'self-insert-command))))
(defun recentf-ido-find-file ()
"Find a recent file using Ido."
(interactive)
(let ((file (ido-completing-read "Choose recent file: " recentf-list nil t)))
(when file
(find-file file))))
:bind
;("C-x C-i" . ido-imenu) ; no ido menu library
("C-x M-f" . ido-find-file-other-window)
("C-x F" . recentf-ido-find-file)
;("C-x C-b" . ibuffer)
(:map ido-file-completion-map
(("C-~" . my/ido-go-straight-home)
("C-w" . ido-delete-backward-updir)
("C-x C-w" . ido-copy-current-file-name)
("~" . (lambda () (interactive) (if
(looking-back "/")
(insert "~/")
(call-interactively 'self-insert-command))))))
:config
; turning off ido faces and on flex matching faces
(setq ido-enable-flex-matching t)
(setq ido-use-faces nil)
(setq ido-enable-prefix nil
ido-enable-flex-matching t
ido-case-fold nil
ido-auto-merge-work-directories-length -1
ido-create-new-buffer 'always
ido-use-filename-at-point nil
ido-max-prospects 10)
(setq flx-ido-use-faces t)
;; Always rescan buffer for imenu
(set-default 'imenu-auto-rescan t)
(global-unset-key (kbd "C-x TAB"))
);use package flx-ido
;(define-key ido-completion-map (kbd "C-i") 'ido-exit-minibuffer )
(use-package flx-isearch )
Flex-Ido and Flex-Search provide search functionality for your mini-buffer dropdown functions.
This enables you to search, say recent files, using fuzzy matching.
Ido Packages
(use-package ido-at-point)
;ido-ubiquitous has an unsolved bug with declared variables
; unbind them
(defvar ido-cur-item nil)
(defvar ido-default-item nil)
(defvar ido-cur-list nil)
;(defvar predicate nil)
;(defvar inherit-input-method nil)
(use-package ido-ubiquitous)
(use-package ido-vertical-mode
:config
(ido-vertical-mode t)
;; C-n/p is more intuitive in vertical layout
(setq ido-vertical-define-keys 'C-n-C-p-up-down-left-right)
);end use package
(require 'ido-at-point)
(ido-at-point-mode)
;whatever
;; Fix ido-ubiquitous for newer packages
;(defmacro ido-ubiquitous-use-new-completing-read (cmd package)
; `(eval-after-load ,package
; '(defadvice ,cmd (around ido-ubiquitous-new activate)
; (let ((ido-ubiquitous-enable-compatibility nil))
; ad-do-it))))
;; Ido at point (C-,)
;; Use ido everywhere
;(ido-ubiquitous-mode 1)
;(ido-ubiquitous-use-new-completing-read webjump 'webjump)
;(ido-ubiquitous-use-new-completing-read yas-expand 'yasnippet)
;(ido-ubiquitous-use-new-completing-read yas-visit-snippet-file 'yasnippet)
It's still good to have ido-mode kicking around, in case you every need it. There's little-to-no penalty to load-time performance.
Ivy
(use-package ivy
;:ensure t
;:disabled t
;:commands (ivy-mode)
:config
(setq ivy-wrap t
ivy-virtual-abbreviate 'full
ivy-use-virtual-buffers t
ivy-use-selectable-prompt t
ivy-count-format "(%d/%d) "
ivy-re-builders-alist '((read-file-name-internal . ivy--regex-fuzzy)
(t . ivy--regex-plus))
ivy-on-del-error-function nil
ivy-initial-inputs-alist nil
enable-recursive-minibuffers t)
;; Use different regex strategies per completion command
;(push '(completion-at-point . ivy--regex-fuzzy) ivy-re-builders-alist) ;; This doesn't seem to work...
;(push '(swiper . ivy--regex-ignore-order) ivy-re-builders-alist)
(push '(counsel-M-x . ivy--regex-ignore-order) ivy-re-builders-alist)
;; Set minibuffer height for different commands
(setf (alist-get 'counsel-projectile-ag ivy-height-alist) 15)
(setf (alist-get 'counsel-projectile-rg ivy-height-alist) 15)
;(setf (alist-get 'swiper ivy-height-alist) 15)
(setf (alist-get 'counsel-switch-buffer ivy-height-alist) 7)
(ivy-mode 1)
:bind (
("C-s" . isearch-forward)
:map ivy-minibuffer-map
("C-i" . ivy-alt-done)
("C-l" . ivy-dispatching-call); l for list
("C-o" . ivy-dispatching-done); o for other
("C-n" . ivy-next-line)
("C-p" . ivy-previous-line)
:map ivy-switch-buffer-map
("C-l" . ivy-dispatching-call); l for list
("C-o" . ivy-dispatching-done); o for other
("C-n" . ivy-next-line)
("C-p" . ivy-previous-line)
("C-d" . ivy-switch-buffer-kill); d for delete
:map ivy-reverse-i-search-map
("C-p" . ivy-previous-line)
("C-d" . ivy-ivy-kill-buffer))
);end ivy
The code chunk above is the stuff you need use ivy and ivy-rich with counsel.
Note that the Counsel configuration in this post includes `:after ivy` .
If you don't include `:after ivy` in your counsel configuration, the ivy code has to appear in the intitialization file before the counsel code.
Ivy Prescient
(use-package ivy-prescient
:after ivy
:commands (ivy-prescient-mode)
;:ensure t
;:init (ivy-prescient-mode)
);end ivy-prescient
You only need ivy-prescient if you're using prescient.el to sort and filter candidates. Note I use the :commands directive to prevent loading the code at initialization.
Ivy Todo (tagging files)
(use-package ivy-todo
;:ensure t
:commands (ivy-todo set-ivy-todo-file)
:config
;set default tags
(setq ivy-todo-default-tags '("TODO" "NEXT" "DEADLINE" "DONE" "CANCELLED"))
;set default ivy-todo-file
(setq ivy-todo-file org-agenda-file)
;inhibit ivy guessing
(setq ivy-todo-guess-list nil)
(defun set-ivy-todo-file(astring)
"Paste file path as to replace ivy-todo-file.
Now you use ivy-todo to manage file."
(interactive "sAstring: ")
(setq ivy-todo-file astring))
);end ivy-todo
I use an org-mode agenda manager, ivy-todo allows you to add todos from your ivy-counsel combo.
Smart Meta X (default)
; Smart M-X, still around if you get sick of helm
(use-package smex
:commands (smex sex-major-mode-commands smex-initialize)
:bind
("C-M-x" . smex)
;("M-X" . smex-major-mode-commands)
);end use package smex
Again, Smart Meta X is good to have around as a backup.