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


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 toand. Use either or rebind. I don't usually go to the thumb so I'm not too frequently moving with the meta key (ALT). For example, I'm not using M-p, M-n for jumping paragraphs, and C-M-f or C-M-b, moving back/forward by word often. The Avy package, here bound to M-s is apparently great for jumping to targets, but I'm not yet using it often. Same with leaving a mark with C-SPC then popping to mark later with C-0. I usually use C-s search to cycle through the words I'm looking for (actually now it's bound to helm search, which I like a little less than ido search, because you have to hit enter, but it still gets you around). Sometimes if there is no memorable landmark near, I'll insert a weird word into a file then use search to get back to it.

 ; 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)

(blink-cursor-mode 0)

;Push the mouse out of the way when the cursor approaches.
(mouse-avoidance-mode 'jump)

(use-package smooth-scrolling
(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)

;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)

(bind-key "C-0" 'pop-to-mark-command)

;Move with M-s
(use-package avy
("M-s" . avy-goto-char));end avy
;Move by sections of lines rather than lines

(use-package mwim
("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.

(defun delete-all-other-buffers ()
    (mapc 'kill-buffer (cdr (buffer-list (current-buffer)))))

;Create scratch buffer
(defun new-frame-scratch-buffer ()
"Create a new scratch buffer -- \*hello-world\*"
  (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
          ;; 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
(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)
([remap other-window] . switch-window)
);end switch window
;enlarge/shrink window
(bind-key "C-<up>" 'enlarge-window)
(bind-key "C-<down>" 'shrink-window)

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

  (  ("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)

emacs posiedon configuration code windows, frames, and buffers hydra

That’s all for now…