This post covers the first two sections from the "Default Operations" section of my init.
Default Operations
- Moving the Cursor and Screen
- Make/kill/move windows frames buffers
- Projectile, Helm and Smex
- Parentheses
- Directories
- Clip board (kill ring)
- PDF tools and command line history
Preamble
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 1115 - 1195. This post covers lines 1195 - 1366. 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.
Moving The Cursor and Screen
I added some spaces between these sections. Saving point, and adjusting the scroll behaviour are standard Emacs defaults you want to set. Copy paste these defaults and that's fine. Mwim is great for changing up C-a, C-e, which are end of sentence and beginning of sentence. What I use to move around the most are C-p, C-n, C-a, and C-e. I also use M-< and M->, which are bound to beginning of page and end of page, though in the code below they are bound to
; Don't highlight matches with jump-char - it's distracting
(setq jump-char-lazy-highlight-face nil)
; Scroll 1 line at a time
(setq scroll-step 1)
; Save point position between sessions
(require 'saveplace)
(setq-default save-place t)
(setq save-place-file (expand-file-name ".places" save-place-file-p))
;Fix the whole huge-jumps-scrolling-between-windows nastiness
(setq scroll-conservatively 1000)
;"Don't hscroll unless needed"- ? More voodoo lisp.
(setq hscroll-margin 1)
;Keeps cursor in the same relative row during pgups and dwns
(setq scroll-preserve-screen-position t)
;Accelerate the cursor when scrolling.
(load "accel" t)
;;Start scrolling when 2 lines from top/bottom
(setq scroll-margin 8)
;cursor
(blink-cursor-mode 0)
;Push the mouse out of the way when the cursor approaches.
(mouse-avoidance-mode 'jump)
(use-package smooth-scrolling
:config
(require 'smooth-scrolling)
(smooth-scrolling-mode t)
(setq smooth-scroll/vscroll-step-size 1)
(setq smooth-scroll/hscroll-step-size 1)
(setq fast-but-imprecise-scrolling t)
:diminish)
;scroll other window
(bind-key "C-M-n" 'helm-scroll-other-window-down)
(bind-key "C-M-p" 'helm-scroll-other-window)
;backward/forward paragraph
(bind-key "M-p" 'backward-paragraph)
(bind-key "M-n" 'forward-paragraph)
;pop-to-mark-command
(bind-key "C-0" 'pop-to-mark-command)
;Move with M-s
(use-package avy
:bind
("M-s" . avy-goto-char));end avy
;Move by sections of lines rather than lines
(use-package mwim
:bind
("C-a" . mwim-beginning-of-code-or-line)
("C-e" . mwim-end-of-code-or-line));end mwim
;beginning end of buffer
(bind-key "<home>" 'beginning-of-buffer)
(bind-key "<end>" 'end-of-buffer)
Make/Kill/Move Frames, Windows, and Buffers
Delete-all-other-buffers and new-frame-scratch-buffer are two functions I use a lot! I like to have a lot of frames open and cycle through them with tab, and you always get a lot of buffers open. My fix is to kill all the frames either with C-x 0, or with a kill frames command, then I open and jump to a scratch buffer and kill all the buffers but the one I'm. It's easier than a restart when you want to clear out your last session and start new. I rarely rotate windows, but I do use frame commands now and then. The switch window package is a little annoying. C-x-o jumps you from one window to another window unless you have more than two open, then switch window gives you a letter to choose. Without switch window you cycle through the open windows, maybe better but you sometimes forget where you are.
;delete-all-buffers
(defun delete-all-other-buffers ()
(interactive)
(mapc 'kill-buffer (cdr (buffer-list (current-buffer)))))
;Create scratch buffer
(defun new-frame-scratch-buffer ()
"Create a new scratch buffer -- \*hello-world\*"
(interactive)
(let ((n 0)
bufname buffer)
(catch 'done
(while t
(setq bufname (concat "*hello-world"
(if (= n 0) "" (int-to-string n))
"*"))
(setq n (1+ n))
(when (not (get-buffer bufname))
(setq buffer (get-buffer-create bufname))
(with-current-buffer buffer
(emacs-lisp-mode))
;; When called non-interactively, the `t` targets the other window (if it exists).
(throw 'done (display-buffer buffer '(display-buffer-pop-up-frame .( (window-height .8) (window-width .8)))
)) )))))
; rotate windows
(defun rotate-windows (arg)
"Rotate your windows; use the prefix argument to rotate the other direction"
(interactive "P")
(if (not (> (count-windows) 1))
(message "You can't rotate a single window!")
(let* ((rotate-times (prefix-numeric-value arg))
(direction (if (or (< rotate-times 0) (equal arg '(4)))
'reverse 'identity)))
(dotimes (_ (abs rotate-times))
(dotimes (i (- (count-windows) 1))
(let* ((w1 (elt (funcall direction (window-list)) i))
(w2 (elt (funcall direction (window-list)) (+ i 1)))
(b1 (window-buffer w1))
(b2 (window-buffer w2))
(s1 (window-start w1))
(s2 (window-start w2))
(p1 (window-point w1))
(p2 (window-point w2)))
(set-window-buffer-start-and-point w1 b2 s2 p2)
(set-window-buffer-start-and-point w2 b1 s1 p1)))))))
; to make a new scratch buffer in a new frame
(bind-key "C-c b" 'new-frame-scratch-buffer)
;to kill a frame in emacs (also, C-x 0)
(bind-key "C-x C-c" 'delete-frame)
;make a new frame
(bind-key "C-x C-n" 'make-frame-command)
;Copy/p frame-cmds.el & frame-fnc.el to frame-cmds directory
(require 'frame-cmds)
(bind-key "M-S-<up>" 'move-frame-up)
(bind-key "M-S-<right>" 'move-frame-right)
(bind-key "M-S-<down>" 'move-frame-down)
(bind-key "M-S-<left>" 'move-frame-left)
(bind-key "C-M-<up>" 'enlarge-frame)
(bind-key "C-M-<right>" 'enlarge-frame-horizontally)
(bind-key "C-M-<down>" 'shrink-frame)
(bind-key "C-M-<left>" 'shrink-frame-horizontally)
;Switch Windows
(use-package switch-window
:defer t
:config
(setq switch-window-input-style 'minibuffer
switch-window-threshold 2
switch-window-increase 4
switch-window-shortcut-style 'qwerty
switch-window-qwerty-shortcuts '("f" "k" "j" "d" "s" "l")
switch-window-auto-resize-window t
switch-window-default-window-size 0.6)
:bind
([remap other-window] . switch-window)
);end switch window
;enlarge/shrink window
(bind-key "C-<up>" 'enlarge-window)
(bind-key "C-<down>" 'shrink-window)
;hydra-buffers-frames
Here's the hydra for buffers frames and windows:
;define a title function
(defvar frames-buffers-title (with-faicon "clone" "FRAMES AND BUFFERS"))
;generate hydra
(pretty-hydra-define Frames-Buffers (:foreign-keys warn :title frames-buffers-title :quit-key "q" :color pink )
("Delete, Make and Switch"
(("d" delete-all-other-buffers "Delete All Other Buffers")
("f" delete-frame "Delete This Frame" )
("F" delete-other-frames "Delete All Other Frames" )
("s" new-frame-scratch-buffer "Make New Scratch Frame" )
("m" make-frame-command "Open A New Frame")
("o" switch-window "Switch To Other Window")
("r" rotate-windows "Rotate Windows")
);end delete
"Move Frames And Windows"
(
("U" move-frame-up "Move Up M-S-<up>")
(">" move-frame-right "Move Right M-S-<right>")
("D" move-frame-down "Move Down M-S-<down>" )
("<" move-frame-left "Move Left M-S-<left>" )
("E" enlarge-frame-horizontally "Horizontal Grow C-M-<right>")
("L" shrink-frame-horizontally "Horizontal Shrink C-M-<left>" )
) ;end Move frames and windows
"EXIT"
( ("G" enlarge-frame "Enlarge Frame C-M-<up>" )
("g" shrink-frame "Shrink Frame C-M-<down>" )
("W" enlarge-window "Enlarge Window C-<up>" )
("w" shrink-window " Shrink Window C-<down>")
("h" hydra-helm/body "Return To Helm" :color blue )
("<SPC>" nil "Quit" :color blue )
);end exit
);end hydra body
);end pretty-hydra-appearance
(bind-key "<C-m> f" 'Frames-Buffers/body)