[Emacs] ediff marked files in dired

Found an awesome trick online to run ediff on marked files in dired.

(defun dired-ediff-marked-files ()
    "Run ediff on marked ediff files."
    (interactive)
    (set 'marked-files (dired-get-marked-files))
    (when (= (safe-length marked-files) 2)
        (ediff-files (nth 0 marked-files) (nth 1 marked-files)))

    (when (= (safe-length marked-files) 3)
        (ediff3 (buffer-file-name (nth 0 marked-files))
                (buffer-file-name (nth 1 marked-files))
                (buffer-file-name (nth 2 marked-files)))))


Another way (link)

(defun mkm/ediff-marked-pair ()
  "Run ediff-files on a pair of files marked in dired buffer"
  (interactive)
  (let* ((marked-files (dired-get-marked-files nil nil))
         (other-win (get-window-with-predicate
                     (lambda (window)
                       (with-current-buffer (window-buffer window)
                         (and (not (eq window (selected-window)))
                              (eq major-mode 'dired-mode))))))
         (other-marked-files (and other-win
                                  (with-current-buffer (window-buffer other-win)
                                    (dired-get-marked-files nil)))))
    (cond ((= (length marked-files) 2)
           (ediff-files (nth 0 marked-files)
                        (nth 1 marked-files)))
          ((and (= (length marked-files) 1)
                (= (length other-marked-files) 1))
           (ediff-files (nth 0 marked-files)
                        (nth 0 other-marked-files)))
          (t (error "mark exactly 2 files, at least 1 locally")))))

[Git] Remove files from last commit

You made a commit which has files that should not have been there. Worry not!

git reset --soft HEAD~1   // to soft reset (preserve changes)
git reset HEAD  /files/you/wish/to/unstage


You can now commit the staged files and checkout the unstaged files

git commit 
git checkout /files/you/wish/to/checkout


That's it!

[Emacs] Keyboard Macros!

Emacs keyboard macros are fun to use.

C-x ( to start recording
C-x ) to stop recording
C-x e to execute


If you want to repeat the macro N number of times,

C-u N C-x e

[Emacs] xterm mouse mode

Found another gem -- in order to use mouse in console mode (emacs -nw) use:

M-x xterm-mouse-mode

Provides basic functionality like scrolling and window selection. Best use when using gdb

[Emacs] Enable line numbers

Add the following to the .emacs file.

;; Show line numbers
(global-linum-mode t)
;; Separate text with space and |
(setq linum-format "%4d \u2502 ")

[Emacs] How to insert newline when replacing strings

To insert newline with replace-string use C-q C-j

e.g.

This;is;a;test

M-x replace-string <RET> ; <RET> C-q C-j

This
is
a
test