This post covers Projectile, Helm, Smex, and Bookmarks from the "Default Operations" section of my init.
- Moving the Cursor and Screen
- Make/kill/move windows frames buffers
- Projectile, Helm and Smex
- Clip board (kill ring)
- PDF tools and command line history
Emacs is old school. You're either new to it - which means you wouldn't be here unless it was your type of thing - or you know what you're looking for. In either case, go to the side bar of this page and click on the 'Emacs' tag. Then read the posts y date from oldest to newest.
In the last emacs post I covered lines 1195 - 1366. This post covers lines 1377 - 1649. I include the lines for anyone that wants to patch together the entire init from start to finish. The lines won't always match up because I take stuff out when I'm in the init.
Projectile, Helm, Smex, and Bookmarks
Projectile is a big package with a lot of popular functionality. I haven't explored it a ton, but it automagically localizes functions to a directory. This is helpful if you have big project directories and you want to save time finding and switching files. You just switch projects and use the projectile functions to search directories and files, open up files in an adjacent window, and so on. There's an indexing method that uses either emacs lisp (the one I'm using below), a hybrid of lisp and the your ops find program, or just your ops find program. The alien method optimizes the hybrid method which you want on Windows, only you have to get windows to use some linux search utilities. I use a windows compiled ag.exe instead of Windows find.exe, but it's still slow, especially with caching. The native indexing method in lisp is also slow. Projectile works fine for me when I turn of caching and minimize the indexing, but in the end unless I have a massive directory, it's just faster for me to use bookmarks, which is what I do 95% of the time. Still, here's the code I use.
;projectile add .projectile to any file (use-package projectile :config (projectile-global-mode) (setq projectile-enable-caching t) ;(setq projectile-indexing-method 'alien) (setq projectile-indexing-method 'hybrid) ;(setq projectile-indexing-method 'native) (setq projectile-sort-order 'recently-active) ;(setq projectile-switch-project-action 'projectile-dired) ;enable safe local variables (setq enable-local-variables ':safe) (setq enable-local-eval ':safe) (setq projectile-completion-system 'helm) (setq projectile-switch-project-action 'helm-projectile) (define-key projectile-mode-map (kbd "C-c p") 'projectile-command-map) ;:bind ("C-c p" . projectile-command-map) ;(setq projectile-enable-caching t) (with-eval-after-load 'projectile (defun projectile-find-file-other-window (&optional invalidate-cache) "Jump to a project's file using completion and show it in another window. With a prefix arg INVALIDATE-CACHE invalidates the cache first." (interactive "P") (progn (setq split-window-preferred-function 'split-window-sensibly) (projectile--find-file invalidate-cache #'find-file-other-window) (setq split-window-preferred-function nil) );end progn ));end redfined projectile function (setq projectile-mode-line-function '(lambda () (format " Projectile[%s]" (projectile-project-name)))) );end projectile
And here is the projectile hydra with code below it.
;define with-octicon function, to use in engine-mode title (defun with-octicon (icon str &rest height v-adjust) (s-concat (all-the-icons-octicon icon :v-adjust (or v-adjust 0) :height (or height 1)) " " str)) (defvar projectile-title (with-octicon "briefcase" "Projectile")) ;generate hydra (pretty-hydra-define Projectile (:title projectile-title :quit-key "q" :color teal ) ("This Frame/Window" ( ("s" helm-projectile-switch-project "Switch Projects") ("f" helm-projectile-find-file "Find File In Project") ("n" helm-projectile-find-file-in-known-projects "Find File In All Projects") ("d" helm-projectile-find-dir "Find Dir In Project") ("p" helm-projectile-find-file-dwim "Find File At Point") ("r" helm-projectile-recentf "Find Recent Files") ("b" helm-projectile-switch-to-buffer "Switch Buffers") ("a" helm-projectile-ag "Search Project") );end local "Other Frame/Window" ( ("F" projectile-find-file-other-frame "Find File Other Frame") ("w" projectile-find-file-other-window "Find File Other Window") ("o" projectile-find-other-file-other-window "Find Other Other Window") ("B" projectile-switch-to-buffer-other-window "Switch Buffer Other Window") ("m" projectile-multi-occur "Search Multi Occurances") );end chrome "Actions" ( ; ("i" projectile-initiate-project "Add .projectile To Dir") ("c" projectile-edit-dir-locals "Add Project Config") ("I" projectile-invalidate-cache "Clear Projectile Cache") ("S" projectile-run-shell "Run Shell") ("v" projectile-save-project-buffers "Save Project Buffers") ("k" projectile-kill-project-buffers "kill Project Buffers") ("t" projectile-toggle-read-only "Toggle Project Read Only") ("D" projectile-discover-projects-in-directory "Discover Projects Directory") ("h" hydra-helm/body "Return To Helm" :color blue ) ("<SPC>" nil "Quit" :color blue ) );end addressbook );end hydra body );end pretty-hydra-find-files (bind-key "<C-m> j" 'Projectile/body)
Helm, Helm Emmet, Helm Projectile
Helm is great. It partitions the screen temporarily with dropdowns you can scroll. There are actions you can call on helm functions that automate frequently used related functions. With my hydra system, I rarely use the actions, but I've gotten used to the helm way. Below the helm initialization code. Check the defaults, fuzzy matching and so on, they matter, but keep your eye open for overkill 😉 . I used to use Smart MetaX, SMEX, for dropdowns, and IDO search for searching through the open buffer. I still prefer IDO search (I Search)to Helm occur, because when you search a second time it doesn't reset the search to the beginning of the buffer and cycling through the helm mini-buffer isn't as visually appealing as cycling through the physical file. I programmed I search within easy reach, and the reverse I search, that I have bound to C-r, doesn't trigger Helm Occur. Still, I haven't bothered to stop using Helm Occur, meaning it's not so bad that I have to change it again. There's a function in here called "better-helm", which is great when you are using projectile and want to include those files in your helm search. If you disable projectile comment out these lines of code ';helm-source-projectile-files-list' and ';helm-source-projectile-buffers-list.'
There are a couple of other packages in here, "helm-projectile", "helm-helm-commands," "helm-chrome", and "helm-mode-manager", "helm-bookmark" (you need to get the file manually and add the path), helm-fuzzier, and "helm-emmet". I use helm-chrome, helm-bookmark, and helm-fuzzier the most, but check them all out. Helm-fuzzier jumps helm to any sequenced characters you type in the search set, helm-chrome gives a searchable dropdown of your chrome bookmarks. So that's great. Helm-bookmark does the same with all your bookmarks. Here's the code. I short-cutted helm-emmet in web-dev hydra. It's sometimes a useful option as you can see the emmet expansions and cycle through them. You can do the same with Company-mode, which is how I usually do it. Still, it's convenient sometimes. Here's the code.
;Helm (use-package helm :defer 3 :diminish helm-mode :init (progn (require 'helm-config) (helm-mode 1) ; (set-face-attribute 'helm-selection nil ; :background "purple" ; :foreground "black") (setq helm-candidate-number-limit 100) (setq helm-idle-delay 0.0 helm-input-idle-delay 0.01 helm-yas-display-key-on-candidate t helm-quick-update t helm-M-x-requires-pattern nil)) (setq-default helm-M-x-fuzzy-match t helm-buffers-fuzzy-matching t helm-recentf-fuzzy-match t helm-imenu-fuzzy-match t helm-locate-fuzzy-match t helm-apropos-fuzzy-match t helm-lisp-fuzzy-completion t helm-allow-mouse t helm-follow-mode-persistent t helm-semantic-fuzzy-match t helm-session-fuzzy-match t helm-etags-fuzzy-match t helm-mode-fuzzy-match t helm-completion-in-region-fuzzy-match t helm-fuzzier-mode t );end-set-q (setq helm-autoresize-max-height 35 helm-autoresize-min-height 35) (when (executable-find "curl") (setq helm-google-suggest-use-curl-p t)) (setq helm-split-window-in-side-p t ; helm-move-to-line-cycle-in-source 0 helm-ff-search-library-in-sexp t helm-scroll-amount 8 helm-ff-file-name-history-use-recentf t helm-echo-input-in-header-line t helm-source-names-using-follow '("Buffers" "kill-buffer" "Occur")) (setq helm-grep-ag-command "rg --color=always --colors 'match:fg:black' --colors 'match:bg:yellow' --smart-case --no-heading --line-number %s %s %s" helm-grep-ag-pipe-cmd-switches '("--colors 'match:fg:black'" "--colors 'match:bg:yellow'")) :config (add-to-list 'helm-sources-using-default-as-input 'helm-source-man-pages) ;(add-to-list 'helm-completing-read-handlers-alist ; '(read-ido . nil)) (require 'helm-buffers) (require 'helm-for-files) (require 'shell) (defun better-helm () (interactive) (let ((helm-ff-transformer-show-only-basename nil) helm-source-list) (unless helm-source-buffers-list (setq helm-source-buffers-list (helm-make-source "Buffers" 'helm-source-buffers))) (cond ( ;; Just add helm-source-projectile-* in list when current place in project. (projectile-project-p) (setq helm-source-list '( ;; helm-source-awesome-tab-group helm-source-projectile-buffers-list helm-source-buffers-list helm-source-recentf helm-source-projectile-files-list))) (t (setq helm-source-list '( ;; helm-source-awesome-tab-group helm-source-buffers-list helm-source-recentf)))) (helm-other-buffer helm-source-list "*helm search*")));end better helm ;yes (setq helm-command-prefix-key "C-c h") (define-key helm-map (kbd "<tab>") 'helm-execute-persistent-action) (define-key helm-map (kbd "C-i") 'helm-execute-persistent-action) (define-key helm-map (kbd "C-z") 'helm-select-action) (define-key shell-mode-map (kbd "C-c C-l") 'helm-comint-input-ring) (define-key minibuffer-local-map (kbd "C-c C-l") 'helm-minibuffer-history) :bind ( ("M-x" . helm-M-x) ("M-y" . helm-show-kill-ring) ("M-b" . better-helm) ;("C-o" . helm-occur) ("C-s" . helm-occur) ("C-x C-f" . helm-mini) ("C-x f" . helm-find-files) ("C-x c x" . helm-register) ("C-x c g" . helm-google-suggest) ("C-x c M-:" . helm-eval-expression-with-eldoc)) :hook (after-init . helm-mode) (after-init . helm-autoresize-mode) );end use-package helm ; Helm Projectile (use-package helm-projectile :defer 5 :init (setq projectile-completion-system 'helm) :config (require 'helm-projectile) :bind ("C-c p h" . helm-projectile) :hook (after-init . helm-projectile-on) );end package helm projectile ;helm find helm commands ;helm-commands-comands (use-package helm-helm-commands :commands helm-helm-commands );end helm-helm-commands ;helm fuzzier matching (use-package helm-fuzzier :config (require 'helm-fuzzier) (helm-fuzzier-mode 1) );helm-fuzzier ;helm-mode-manager (use-package helm-mode-manager :commands (helm-switch-major-mode helm-enable-minor-mode helm-disable-minor-mode helm-mode-manager-describe-mode helm-mode-manager-list-major-modes) :config (require 'helm-mode-manager) );end helm-mode-manager ;helm-chrome (bookmark manager) (use-package helm-chrome :commands (helm-chrome-bookmarks helm-chrome-reload-bookmarks) :defer t :config (require 'helm-chrome ) (setq helm-chrome-use-urls t) );end helm-chrome ;helm-css-scss ;(use-package helm-css-scss ;:commands (helm-css-scss-multi helm-css-scss-insert-close-comment) ;);end helm-css-scss ;helm emmet (use-package helm-emmet :commands (helm-emmet) );end helm-edit ;helm-bookmark (add-to-list 'load-path helm-bookmark-p) (require 'helm-bookmark)
SMEX, Address book, and Helm-Addressbook
SMEX is good to have around if you ever want to use it. The address book is so so. It integrates with your regular bookmarks, which is annoying. It would better if you could call it separately. Nonetheless, here is the code for that and the associated helm package.
; Smart M-X, still around if you get sick of helm (use-package smex :bind ("C-M-x" . smex) ;("M-X" . smex-major-mode-commands) );end use package smex ;addressbook-bookmark (use-package addressbook-bookmark :after helm-addressbook :commands (addressbook-bookmark-set helm-addressbook-bookmarks) );end package addressbook-bookmark ;helm-addressbook bookmark (use-package helm-addressbook );end-use-package helm address book ;bookmarks configuration (setq bookmark-default-file bookmarks-p)
Here's the bookmark hydra, which I used all the time
;bookmark hydra (defvar bookmarks-title (with-faicon "book" "Manage Book Marks")) ;generate hydra (pretty-hydra-define Bookmarks (:title bookmarks-title :quit-key "q" :color teal ) ("Local Bookmarks" ( ("b" helm-bookmarks "Jump To A Bookmark") ("s" bookmark-set "Set A Bookmark") ("e" edit-bookmarks "Edit Bookmarks") );end local "Chrome Bookmarks" ( ("c" helm-chrome-bookmarks "Select A Chrome Bookmark") ("r" helm-chrome-reload-bookmarks "Refresh Chrome Bookmarks") );end chrome "Address Book" ( ("a" addressbook-bookmark-set "Enter Contact To Addressbook") ("h" hydra-helm/body "Return To Helm" :color blue ) ("<SPC>" nil "Quit" :color blue ) );end addressbook );end hydra body );end pretty-hydra-find-files (bind-key "<C-m> m" 'Bookmarks/body)