Updated March 18, 2021

Most of my code has changed a lot recently. Check updated posts.

For each post can update code listed in that post. Keep in mind code for linux and wsl configs will have their own posts, except in the case of .early-init and init.el, which have system switches (to load system specific dot-files).

Also note: abandoned convention of listing init lines. Now if you want to find the code, and there is now plenty of decent emacs code, use the search function. The site is not large.

Bookmark


1
2
3
4
5
6

(setq bookmark-default-file bookmarks-p)
(global-set-key (kbd "C-c d") 'counsel-bookmarked-directory)
(global-set-key (kbd "C-c f") 'counsel-bookmark)
(global-set-key (kbd "C-c s") 'bookmark-set)


Using now counsel-bookmark.

BM Bookmark


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81

(use-package bm
:init
(setq bm-restore-repository-on-load t)
:config

;; Allow cross-buffer 'next'
(setq bm-cycle-all-buffers t)

;; where to store persistant files
(setq bm-repository-file "~/.emacs.d/bm-repository")

;; save bookmarks
(setq-default bm-buffer-persistence t)

;; Loading the repository from file when on start up.
(add-hook 'after-init-hook 'bm-repository-load)

;; Saving bookmarks
(add-hook 'kill-buffer-hook #'bm-buffer-save)

;; Saving the repository to file when on exit.
;; kill-buffer-hook is not called when Emacs is killed, so we
;; must save all bookmarks first.
(add-hook 'kill-emacs-hook #'(lambda nil
											(bm-buffer-save-all)
											(bm-repository-save)))



;; Restoring bookmarks
(add-hook 'find-file-hooks   #'bm-buffer-restore)
(add-hook 'after-revert-hook #'bm-buffer-restore)

;; Make sure bookmarks is saved before check-in (and revert-buffer)
(add-hook 'vc-before-checkin-hook #'bm-buffer-save)

;the two functions that make bm-bookmark worth it.
(defun poseidon/bm-counsel-get-list (bookmark-overlays)
	 "TODO: docstring.
 Arguments: BOOKMARK-OVERLAYS."
	 (-map (lambda (bm)
			 (with-current-buffer (overlay-buffer bm)
			   (let* ((line (replace-regexp-in-string
							 "\n$"
							 ""
							 (buffer-substring (overlay-start bm)
											   (overlay-end bm))))
					  ;; line numbers start on 1
					  (line-num (+ 1 (count-lines (point-min) (overlay-start bm))))
					  (name (format "%s:%d - %s" (buffer-name) line-num line)))
				 `(,name . ,bm))))
		   bookmark-overlays))


 (defun poseidon/bm-counsel-find-bookmark ()
	 "TODO: docstring.
 Arguments: none."
	 (interactive)
	 (let* ((bm-list (poseidon/bm-counsel-get-list (bm-overlays-lifo-order t)))
			(bm-hash-table (make-hash-table :test 'equal))
			(search-list (-map (lambda (bm) (car bm)) bm-list)))
	   (-each bm-list (lambda (bm)
						(puthash (car bm) (cdr bm) bm-hash-table)))
	   (ivy-read "Find bookmark: "
				 search-list
				 :require-match t
				 :keymap counsel-describe-map
				 :action (lambda (chosen)
						   (let ((bookmark (gethash chosen bm-hash-table)))
							 (switch-to-buffer (overlay-buffer bookmark))
							 (bm-goto bookmark)))
				 :sort t)))

;(global-unset-key (kbd "<C-tab>"))
(global-set-key (kbd "M-j") 'bm-toggle)
(global-set-key (kbd "C-c j") 'poseidon/bm-counsel-find-bookmark)
(global-set-key (kbd "C-c ,") 'bm-previous)
(global-set-key (kbd "C-c .") 'bm-next)
);end bm bookmarks


BM Bookmark is useful for session local bookmarks. You can open a tabbed frame with files you want to use in your session, then bookmark them for the session and open another frame with a quad window layout. In your quad window layout you can bring in whatever file you want into whatever window you want. Find a medium between this setup, winner-mode, and shackle.

Dropped helm-bookmark and helm-addressbook, added helm-firefox-bookmarks to helm-chrome-bookmarks

Helm-Firefox-Bookmarks


1
2
3
4
5
6
7
8
9

(setq helm-firefox-default-directory "path-to-firefox-config/AppData/Roaming/Mozilla/Firefox/")
(setq  helm-firefox-bookmark-user-directory "path-to-firefox-bookmarks/emacs-27.1/.emacs.d/firefox-bookmarks/")

(use-package helm-firefox
:commands helm-firefox-bookmarks
;:ensure t
)


New Bookmarks hydra


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49


;bookmark hydra
(setq 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"  counsel-bookmark "Jump To A Bookmark C-c f")
    ("d"  counsel-bookmarked-directory "Jump Bookmarked dir C-c d")
    ("s" bookmark-set "Set A Bookmark")
    ("e" edit-bookmarks "Edit Bookmarks")


);end local
"Session Bookmarks"
(
    ("J"  bm-toggle "Set/Unset Session Bkmrk M-j")
    ("j" poseidon/bm-counsel-find-bookmark  "Call Session Bkmrk C-c j")
    ("m" bm-bookmark-annotate "Annotate Bkmrk")
    ("n" bm-next "bm next")
    ("p" bm-previous "Open in new buffer")
    ("a" bm-show-all  "List session bkmarks")
    ("A" bm-show  "List session bkmarks in buffer")
    ("g" bm-show-goto-bookmark  "Jmp to bkmrk from list")
    ("r" bm-remove-all-current-buffer "Remove buffer session bkmrks ")
    ("R" bm-remove-all-all-buffers "Remove all sesssion bkmrks")
    ("c" bm-toggle-cycle-all-buffers "Cycle All Buffer Bkmarks")

);end chrome
"Address Book"
(
    ("@" addressbook-bookmark-set "Enter Contact To Addressbook")
    ("c" helm-chrome-bookmarks "Select A Chrome Bookmark")
    ("r" helm-chrome-reload-bookmarks "Refresh Chrome Bookmarks")
    ("P" bm-toggle-buffer-persistence "Toggle Bm Persistance")
    ("S" bm-buffer-save-all "Bm save session bmkrks")
    ("+" bm-repository-add "Bm Add Repo")
    ("L" bm-repository-load "Bm Load Repo")
    ("C" bm-repository-clear "Bm Clear Repo")
    ("$" bm-repository-save "Bm Save Repo")
    ("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)



BM Bookmark Hydra


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44


(setq bm-bookmarks-title (with-faicon "book" "Visual Bookmarks Command"))

;generate hydra
(pretty-hydra-define bm-bookmarks (:title bm-bookmarks-title :quit-key "q" :color pink )
("A"
(
    ("J" bm-toggle "Set/unset session bkmrk")
    ("j" poseidon/bm-counsel-find-bookmark  "Counsel Bkmark")
    ("m" bm-bookmark-annotate "Annotate Bkmrk")
    ("n" bm-next "bm next")
    ("p" bm-previous "Open in new buffer")




);end theme
"Bkmark Remove"
(
    ("a" bm-show-all  "List session bkmarks")
    ("A" bm-show  "List session bkmarks in buffer")
    ("g" bm-show-goto-bookmark  "Jmp to bkmrk from list")
    ("r" bm-remove-all-current-buffer "Remove buffer session bkmrks ")
    ("R" bm-remove-all-all-buffers "Remove all sesssion bkmrks")
    ("c" bm-toggle-cycle-all-buffers "Cycle All Buffer Bkmarks")

);end highlighting

"Bkmark Repo"
(
    ("P" bm-toggle-buffer-persistence "Toggle Bm Persistance")
    ("S" bm-buffer-save-all "Bm Save session bmkrks")
    ("+" bm-repository-add "Bm Add Repo")
    ("L" bm-repository-load "Bm Load Repo")
    ("C" bm-repository-clear "Bm Clear Repo")
    ("$" bm-repository-save "Bm Save Repo")
    ("h" hydra-helm/body "Return To Helm" :color blue )
    ("<SPC>" nil "Quit" :color pink)
);end other
);end hydra body
);end pretty-hydra-bookmark
(bind-key "<C-m> j" 'bm-bookmarks/body)


Original Post Below


Jumping To Directories In Emacs

If you want to accomplish things efficiently with your computer, you will benefit from mastering a text editor. I use emacs as a general project manager for web development, writing, and organizing thoughts, materials, and actions. Jumping to and from directories and files enables quickly me to get things done more efficiently. To do this I use a few different packages and functions. They are:

  1. Bookmarks

  2. Projectile

  3. Capture

  4. Dired Mode

  5. Hardwired Jumps

  6. File-find functions: Helm-find, Better-helm, Ido-find etc.

Bookmarks is a package built into emacs. I use it the most. Projectile is a package you add to your emacs configuration. I use projectile a lot as well. It's more useful if you have really large projects with a lot of files in them. If I cover projectile, I'll do it at another time.Org-capture is absolutely amazing. I literally use it every 8 minutes. I absolutely love it. I'll discuss it at another time. Hardwired jumps (that's what I call them) are just calls to dired mode with a path added to a function and triggered through an interface. I use those in a few hydras and there are a few packages that use them as well (like easy-hugo, for example). The find-file functions and dired mode are similar. They are calls you make from the minibuffer to bring up searches. If I do another post about finding files in emacs I'll discuss those as well.

I call the bookmark functions through a bookmark hydra. It has in it chrome bookmarks, helm-address-bookmark (which is just basically bookmarks with another name), and bookmarks. Chrome bookmarks enable you to access your web bookmarks from within emacs. The other bookmarks jump you to a directory or file. You set the bookmark, then jump to it. You can set the functions to a shortcut if you like. I just add them to my hydra network. Here's an image of the bookmarks and some configuration code.


Bookmark Hydra

Here's the chrome bookmarks config code:


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14

;helm-bookmark-p
(defvar helm-bookmark-p "c:/emacs/emax/elpa/helm-bookmarks/helm-bookmark.el")


;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 bookmarks I think you have to download to your path and require. You can get the file here: Helm Bookmarks I add all paths to variables in one early section of my configuration. That way they are easy to change. Later I require the file from the path.


1
2
3
4
5
6
7
8

;line 82
;helm-bookmark-p
(defvar helm-bookmark-p "c:/emacs/emax/elpa/helm-bookmarks/helm-bookmark.el")
;line 1674
(add-to-list 'load-path helm-bookmark-p)
(require 'helm-bookmark)


And here's the configuration for the bookmarks hydra (you need all-the-icons installed and some icon configuration code to get the icon on the hydra.)


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32

;line 129
(defvar bookmarks-p "c://emacs/.emacs.d/default-bookmarks" )
;line 1690
;bookmarks configuration
(setq bookmark-default-file bookmarks-p)
;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)


Here's a video clip:


That’s all for now…

comments powered by Disqus