Searching
Anzu Mode Find and Replace
You can find and replace text and expressions one at a time or all at once.
;show number of matches
(use-package anzu
:diminish
:config
(global-anzu-mode +1)
(global-set-key [remap query-replace] 'anzu-query-replace)
(global-set-key [remap query-replace-regexp] 'anzu-query-replace-regexp)
:hook
(after-init . global-anzu-mode)
);end anzu
;find and replace expressions in an emacs buffer
(global-set-key (kbd "M-&") 'query-replace-regexp)
Swiper
You may find searching your buffer with Swiper more practical than the emacs default, or maybe not.
Here’s the code:
(use-package swiper
:bind* (("C-s" . swiper)
;("C-r" . swiper)
("C-M-s" . swiper-all))
:bind
(:map read-expression-map
("C-r" . counsel-minibuffer-history))
);end swiper
Search Hydra Overview
You can use bookmarks and swiper to navigate to dired locations, like desktop, downloads, documents, dropbox, or key project or storage git repos.
You can use counsel-ibuffer
, ibuffer
, or counsel-buffer-or-recentf
to search through open buffers.
You can use bookmarks
and ag.exe
to jump to a directory and search for text in files.
You can use also ag-files
to do the same, since it's recursive and can narrow down selections with file endings -- not ag-file
, thanks for pointing that out.
You can use helm-org-rifle-agenda-files
to search through files you've marked in your init as agenda files.
Set Agenda Files
You can set agenda files with org-agenda-files
to org-journal
, org-agenda
, or org-clients
, then search files in those directories.
pos-set-agenda-files
cycles and sets the active org-agenda directory.
(with-eval-after-load 'org
(setq org-directory (list
org-journal
org-agenda
org-clients
));end org directory
(setq cur_dir "agenda")
(defun pos-set-agenda-files ()
(interactive)
(cond
; if cmd-shell set to bash
((equal cur_dir "agenda")
(progn
;equal
(setq org-agenda-files (list org-dir-science)); dropbox comp sci files
(setq cur_dir "science")
(message "Agenda files set to: some-path-to-your-notes computer-science-notes/ , toggle again for orgfiles")
);end progn
;else
);end cond 1
;if agenda
((equal cur_dir "science")
(progn
(setq org-agenda-files (list org-dir-p )); dropbox comp sci files
(setq cur_dir "orgfiles")
(message "Agenda files set to: some-other-path-to-other-notes toggle again for agenda files")
));end cond 2
;if science
((equal cur_dir "orgfiles")
(progn
;equal
(setq org-agenda-files (list org-agenda org-clients org-journal)); dropbox agenda files
(setq cur_dir "agenda")
(message "Agenda files set to just: ..orgfiles/agenda/, ..orgfiles/journal/, orgfiles/clients/, toggle again for science files")
));end cond 3
;else set to agenda
(t (progn
(setq org-agenda-files (list org-agenda org-clients org-journal)); dropbox agenda files
;equal
(setq cur_dir "agenda")
(message "Agenda files set to just: ..orgfiles/agenda/, ..orgfiles/journal/, orgfiles/clients/, toggle again for science files")
))
);end conditional
);end pos set agenda files directory
(setq org-agenda-files (list
org-journal
org-agenda
org-clients
));endo org agenda
)
Counsel
You can use counsel to retrieve info on font face colors, libraries, variables and functions.
Here's some code:
(use-package counsel
;:ensure t
:after ivy
:config
; Don't start searches with ^
(setq ivy-initial-inputs-alist nil)
(counsel-mode)
;show org-tags in counsel searches
(setq counsel-org-headline-display-tags t)
;show org-todos in counsel searches
(setq counsel-org-headline-display-todo t)
(define-key ivy-switch-buffer-map (kbd "C-d") 'mu-ivy-kill-buffer)
;ivy-todo calls org-set-tags-command, remap to counsel-org-tag
(global-set-key [remap org-set-tags-command] #'counsel-org-tag)
:bind (
([remap describe-function] . counsel-describe-function)
([remap describe-command] . helpful-command)
([remap describe-variable] . counsel-describe-variable)
([remap describe-key] . helpful-key)
("M-x" . counsel-M-x)
("C-x b" . counsel-switch-buffer)
("C-x C-b" . counsel-ibuffer)
("C-x C-m" . counsel-imenu) ;headers level 1
("C-x C-d" . counsel-bookmarked-directory)
("C-x f" . helm-org-rifle-current-buffer)
("C-x r" . helm-org-rifle)
("C-x C-r" . counsel-recentf)
("C-x C-f" . counsel-find-file)
("C-h b" . counsel-descbinds)
("M-y" . counsel-yank-pop)
("M-SPC" . counsel-shell-history)
:map minibuffer-local-map
("C-r" . 'counsel-minibuffer-history)
("C-d" . ivy-switch-buffer-kill); d for delete
);end bind
);end counsel
Counsel Locate Everything
You can use everything.exe
with counsel-locate
.
Set everything.exe
path to a variable called everything-p
and launch everything.exe
before calling counsel-locate
.
(setq everything-launched 0)
(defun launch-everything ()
(interactive)
(w32-shell-execute nil everything-p nil )
);end launch-excel
(defun pos-counsel-locate()
(interactive)
(if (= everything-launched 0)
(progn
(launch-everything)
(counsel-locate)
(setq everything-launched 1)
);end progn
);end if
(counsel-locate)
);end pos-helm-locate
Counsel Web
You can enable web search in buffers using EWW or the newer linux browser frameworks.
(use-package counsel-web
;:ensure t
:commands (counsel-web-suggest counsel-web-search)
:config
:disabled
;as opposed to in emacs
(setq counsel-web-search-action #'browse-url)
;alternate browser
;(setq counsel-web-search-alternate-action #'w3m)
(setq counsel-web-engine 'google)
;(setq counsel-web-engine 'duckduckgo)
;counsel-web-engine-alist
;update search results with each key press: experimental
(setq counsel-web-search-dynamic-update t)
);
Ivy-Rich
Here is some ivy-rich
code.
(use-package ivy-rich
:after (:and ivy counsel)
;:ensure t
;:commands (counsel-mode)
:init
(setcdr (assq t ivy-format-functions-alist) #'ivy-format-function-line)
(ivy-rich-mode)
:config
;these are david wilsons configurations
(setq ivy-format-function #'ivy-format-function-line)
(setq ivy-rich-display-transformers-list
(plist-put ivy-rich-display-transformers-list
'ivy-switch-buffer
'(:columns
((ivy-rich-candidate (:width 40))
(ivy-rich-switch-buffer-indicators (:width 4 :face error :align right)); return the buffer indicators
(ivy-rich-switch-buffer-major-mode (:width 12 :face warning)) ; return the major mode info
(ivy-rich-switch-buffer-project (:width 15 :face success)) ; return project name using `projectile'
(ivy-rich-switch-buffer-path (:width (lambda (x) (ivy-rich-switch-buffer-shorten-path x (ivy-rich-minibuffer-width 0.3)))))) ; return file path relative to project root or `default-directory' if project is nil
:predicate
(lambda (cand)
(if-let ((buffer (get-buffer cand)))
;; Don't mess with EXWM buffers
(with-current-buffer buffer
(not (derived-mode-p 'exwm-mode))))))))
;:hook
;(after-init . ivy-rich-mode)
);end ivy-rich
Custom Ivy-Rich
If you switch from Helm to Ivy, you may have difficulty getting icons in the minibuffer. You can use use-package emacs
to enter custom code that will up the aesthetics.
(use-package emacs
:after (ivy-rich all-the-icons-ivy-rich)
:config
;; Toggle `ivy-rich-mode' after modifying `ivy-rich-display-transformers-list'.
(setq ivy-rich-display-transformers-list
`(ivy-switch-buffer
(:columns ((all-the-icons-ivy-rich-buffer-icon)
(ivy-switch-buffer-transformer
(:width 0.2))
(ivy-rich-switch-buffer-major-mode
(:width 18 :face warning))
(ivy-rich-switch-buffer-project
(:width 15 :face success))
(ivy-rich-switch-buffer-indicators
(:width 4 :face error :align right))
(ivy-rich-switch-buffer-size
(:width 7))
(ivy-rich-switch-buffer-path
(:width (lambda (x)
(ivy-rich-switch-buffer-shorten-path
x (ivy-rich-minibuffer-width 0.2))))))
:predicate (lambda
(cand)
(get-buffer cand))
:delimiter " ")
ivy-switch-buffer-other-window
(:columns ((all-the-icons-ivy-rich-buffer-icon)
(ivy-rich-candidate
(:width 30))
(ivy-rich-switch-buffer-size
(:width 7))
(ivy-rich-switch-buffer-indicators
(:width 4 :face error :align right))
(ivy-rich-switch-buffer-major-mode
(:width 18 :face warning))
(ivy-rich-switch-buffer-project
(:width 15 :face success))
(ivy-rich-switch-buffer-path
(:width (lambda
(x)
(ivy-rich-switch-buffer-shorten-path
x (ivy-rich-minibuffer-width 0.3))))))
:predicate (lambda
(cand)
(get-buffer cand))
:delimiter " ")
counsel-switch-buffer
(:columns ((all-the-icons-ivy-rich-buffer-icon)
(ivy-rich-candidate
(:width 30))
(ivy-rich-switch-buffer-size
(:width 7))
(ivy-rich-switch-buffer-indicators
(:width 4 :face error :align right))
(ivy-rich-switch-buffer-major-mode
(:width 18 :face warning))
(ivy-rich-switch-buffer-project
(:width 15 :face success))
(ivy-rich-switch-buffer-path
(:width (lambda
(x)
(ivy-rich-switch-buffer-shorten-path
x (ivy-rich-minibuffer-width 0.3))))))
:predicate (lambda
(cand)
(get-buffer cand))
:delimiter " ")
counsel-projectile-switch-to-buffer
(:columns ((all-the-icons-ivy-rich-buffer-icon)
(ivy-rich-candidate
(:width 30))
(ivy-rich-switch-buffer-size
(:width 7))
(ivy-rich-switch-buffer-indicators
(:width 4 :face error :align right))
(ivy-rich-switch-buffer-major-mode
(:width 18 :face warning))
(ivy-rich-switch-buffer-project
(:width 15 :face success))
(ivy-rich-switch-buffer-path
(:width (lambda
(x)
(ivy-rich-switch-buffer-shorten-path
x (ivy-rich-minibuffer-width 0.3))))))
:predicate (lambda
(cand)
(get-buffer cand))
:delimiter " ")
counsel-switch-buffer-other-window
(:columns ((all-the-icons-ivy-rich-buffer-icon)
(ivy-rich-candidate
(:width 30))
(ivy-rich-switch-buffer-size
(:width 7))
(ivy-rich-switch-buffer-indicators
(:width 4 :face error :align right))
(ivy-rich-switch-buffer-major-mode
(:width 18 :face warning))
(ivy-rich-switch-buffer-project
(:width 15 :face success))
(ivy-rich-switch-buffer-path
(:width (lambda
(x)
(ivy-rich-switch-buffer-shorten-path
x (ivy-rich-minibuffer-width 0.3))))))
:predicate (lambda
(cand)
(get-buffer cand))
:delimiter " ")
package-install
(:columns ((ivy-rich-candidate (:width 30))
(ivy-rich-package-version (:width 16 :face font-lock-comment-face)) ; package version
(ivy-rich-package-archive-summary (:width 7 :face font-lock-builtin-face)) ; archive summary
(ivy-rich-package-install-summary (:face font-lock-doc-face)))) ; package description
persp-switch-to-buffer
(:columns ((all-the-icons-ivy-rich-buffer-icon)
(ivy-rich-candidate
(:width 30))
(ivy-rich-switch-buffer-size
(:width 7))
(ivy-rich-switch-buffer-indicators
(:width 4 :face error :align right))
(ivy-rich-switch-buffer-major-mode
(:width 18 :face warning))
(ivy-rich-switch-buffer-project
(:width 15 :face success))
(ivy-rich-switch-buffer-path
(:width (lambda
(x)
(ivy-rich-switch-buffer-shorten-path
x (ivy-rich-minibuffer-width 0.3))))))
:predicate (lambda
(cand)
(get-buffer cand))
:delimiter " ")
counsel-M-x
(:columns ((all-the-icons-ivy-rich-function-icon)
(counsel-M-x-transformer
(:width 50))
(ivy-rich-counsel-function-docstring
(:face font-lock-doc-face))))
counsel-describe-function
(:columns ((all-the-icons-ivy-rich-function-icon)
(counsel-describe-function-transformer
(:width 50))
(ivy-rich-counsel-function-docstring
(:face font-lock-doc-face))))
counsel-describe-variable
(:columns ((all-the-icons-ivy-rich-variable-icon)
(counsel-describe-variable-transformer
(:width 50))
(ivy-rich-counsel-variable-docstring
(:face font-lock-doc-face))))
counsel-set-variable
(:columns ((all-the-icons-ivy-rich-variable-icon)
(counsel-describe-variable-transformer
(:width 50))
(ivy-rich-counsel-variable-docstring
(:face font-lock-doc-face))))
counsel-apropos
(:columns ((all-the-icons-ivy-rich-symbol-icon)
(ivy-rich-candidate))
:delimiter " ")
counsel-info-lookup-symbol
(:columns ((all-the-icons-ivy-rich-symbol-icon)
(ivy-rich-candidate))
:delimiter " ")
counsel-descbinds
(:columns ((all-the-icons-ivy-rich-keybinding-icon)
(ivy-rich-candidate))
:delimiter " ")
counsel-find-file
(:columns ((all-the-icons-ivy-rich-file-icon)
(ivy-read-file-transformer))
:delimiter " ")
counsel-file-jump
(:columns ((all-the-icons-ivy-rich-file-icon)
(ivy-rich-candidate))
:delimiter " ")
counsel-dired
(:columns ((all-the-icons-ivy-rich-file-icon)
(ivy-read-file-transformer))
:delimiter " ")
counsel-dired-jump
(:columns ((all-the-icons-ivy-rich-file-icon)
(ivy-rich-candidate))
:delimiter " ")
counsel-el
(:columns ((all-the-icons-ivy-rich-symbol-icon)
(ivy-rich-candidate))
:delimiter " ")
counsel-fzf
(:columns ((all-the-icons-ivy-rich-file-icon)
(ivy-rich-candidate))
:delimiter " ")
counsel-git
(:columns ((all-the-icons-ivy-rich-file-icon)
(ivy-rich-candidate))
:delimiter " ")
counsel-recentf
(:columns ((all-the-icons-ivy-rich-file-icon)
(ivy-rich-candidate
(:width 0.2))
(ivy-rich-file-last-modified-time
(:face font-lock-comment-face)))
:delimiter " ")
counsel-buffer-or-recentf
(:columns ((all-the-icons-ivy-rich-file-icon)
(counsel-buffer-or-recentf-transformer
(:width 0.2))
(ivy-rich-file-last-modified-time
(:face font-lock-comment-face)))
:delimiter " ")
counsel-bookmark
(:columns ((ivy-rich-bookmark-type)
(all-the-icons-ivy-rich-bookmark-name
(:width 40))
(ivy-rich-bookmark-info))
:delimiter " ")
counsel-bookmarked-directory
(:columns ((all-the-icons-ivy-rich-file-icon)
(ivy-rich-candidate))
:delimiter " ")
counsel-package
(:columns ((all-the-icons-ivy-rich-package-icon)
(ivy-rich-candidate))
:delimiter " ")
counsel-fonts
(:columns ((all-the-icons-ivy-rich-font-icon)
(ivy-rich-candidate))
:delimiter " ")
counsel-major
(:columns ((all-the-icons-ivy-rich-function-icon)
(ivy-rich-candidate))
:delimiter " ")
counsel-find-library
(:columns ((all-the-icons-ivy-rich-library-icon)
(ivy-rich-candidate))
:delimiter " ")
counsel-load-library
(:columns ((all-the-icons-ivy-rich-library-icon)
(ivy-rich-candidate))
:delimiter " ")
counsel-load-theme
(:columns ((all-the-icons-ivy-rich-theme-icon)
(ivy-rich-candidate))
:delimiter " ")
counsel-world-clock
(:columns ((all-the-icons-ivy-rich-world-clock-icon)
(ivy-rich-candidate))
:delimiter " ")
counsel-tramp
(:columns ((all-the-icons-ivy-rich-tramp-icon)
(ivy-rich-candidate))
:delimiter " ")
counsel-git-checkout
(:columns ((all-the-icons-ivy-rich-git-branch-icon)
(ivy-rich-candidate))
:delimiter " ")
counsel-list-processes
(:columns ((all-the-icons-ivy-rich-process-icon)
(ivy-rich-candidate))
:delimiter " ")
counsel-projectile-switch-project
(:columns ((all-the-icons-ivy-rich-file-icon)
(ivy-rich-candidate))
:delimiter " ")
projectile-persp-switch-project
(:columns ((all-the-icons-ivy-rich-file-icon)
(ivy-rich-candidate))
:delimiter " ")
counsel-projectile-find-file
(:columns ((all-the-icons-ivy-rich-file-icon)
(counsel-projectile-find-file-transformer))
:delimiter " ")
counsel-projectile-find-dir
(:columns ((all-the-icons-ivy-rich-project-icon)
(counsel-projectile-find-dir-transformer))
:delimiter " ")
counsel-minor
(:columns ((all-the-icons-ivy-rich-mode-icon)
(ivy-rich-candidate))
:delimiter " ")
counsel-imenu
(:columns ((all-the-icons-ivy-rich-imenu-icon)
(ivy-rich-candidate))
:delimiter " ")
treemacs-projectile
(:columns ((all-the-icons-ivy-rich-file-icon)
(ivy-rich-candidate))
:delimiter " ")))
);end ivy-custom-ivy-rich