This is part of the Emacs Starter Kit.
(global-set-key (kbd "M-\\") 'align-regexp)
(set-default 'indent-tabs-mode nil)
(set-default 'tab-width 4)
(defun move-beginning-of-line-dwim ()
(interactive)
(let* ((orig-point (point))
(cur-point (beginning-of-visual-line)))
(when (and
(= orig-point cur-point)
(= (line-beginning-position) cur-point))
(back-to-indentation))))
(global-set-key [remap move-end-of-line] 'end-of-visual-line)
(with-eval-after-load 'evil
(define-key evil-normal-state-map (kbd "0") 'move-beginning-of-line-dwim)
(define-key evil-normal-state-map (kbd "$") 'end-of-visual-line))
(with-eval-after-load 'org
(define-key org-mode-map (kbd "C-e") 'end-of-visual-line))
(global-set-key (kbd "C-+") 'text-scale-increase)
(global-set-key (kbd "C--") 'text-scale-decrease)
(global-set-key (kbd "C-c c") 'org-capture)
(global-set-key (kbd "C-c l") 'org-store-link)
(with-defhydra
"hydra-org"
global-map
(kbd "C-c o")
("c" org-capture "capture")
("l" org-store-link "storeLink")
("L" org-insert-link "insertLink")
("j" org-clock-goto "clockGoTo")
("a" org-agenda "agenda")
("q" nil "quit"))
(defun xah-toggle-letter-case ()
"Toggle the letter case of current word or text selection.
Toggles between: all lower, Init Caps, ALL CAPS."
(interactive)
(save-excursion
(let (p1 p2 (deactivate-mark nil) (case-fold-search nil))
(if (use-region-p)
(setq p1 (region-beginning) p2 (region-end))
(let ((bds (bounds-of-thing-at-point 'word)))
(setq p1 (car bds) p2 (cdr bds))))
(when (not (eq last-command this-command))
(save-excursion
(goto-char p1)
(cond
((looking-at "[[:lower:]][[:lower:]]") (put this-command 'state "all lower"))
((looking-at "[[:upper:]][[:upper:]]") (put this-command 'state "all caps"))
((looking-at "[[:upper:]][[:lower:]]") (put this-command 'state "init caps"))
((looking-at "[[:lower:]]") (put this-command 'state "all lower"))
((looking-at "[[:upper:]]") (put this-command 'state "all caps"))
(t (put this-command 'state "all lower")))))
(cond
((string= "all lower" (get this-command 'state))
(upcase-region p1 p2)
(put this-command 'state "all caps"))
((string= "all caps" (get this-command 'state))
(downcase-region p1 p2)
(upcase-initials-region p1 p2)
(put this-command 'state "init caps"))
((string= "init caps" (get this-command 'state))
(downcase-region p1 p2)
(put this-command 'state "all lower"))))))
(global-set-key (kbd "M-u") 'xah-toggle-letter-case)
Expand region increases the selected region by semantic units. Just keep pressing the key until it selects what you want.
In terminal, C-= may not work. You may have to run extended-command-history to expand or contract region.
(global-set-key (kbd "C-=") 'er/expand-region)
(key-chord-mode 1)
Use jk key chord to quite everything.
(defun evil-exit-emacs-to-normal ()
(interactive)
(evil-exit-emacs-state)
(evil-normal-state))
(setq key-chord-two-keys-delay 0.05)
(eval-after-load 'evil
`(progn
(key-chord-define evil-insert-state-map "jk" 'evil-normal-state)
(key-chord-define evil-normal-state-map "jk" 'keyboard-quit)
(key-chord-define evil-ex-completion-map "jk" 'abort-recursive-edit)
(key-chord-define evil-emacs-state-map "jk" 'evil-exit-emacs-to-normal)
(key-chord-define evil-visual-state-map "jk" 'evil-exit-visual-state)))
(key-chord-define minibuffer-local-map "jk" 'minibuffer-keyboard-quit)
(key-chord-define minibuffer-local-ns-map "jk" 'minibuffer-keyboard-quit)
(key-chord-define minibuffer-local-completion-map "jk" 'minibuffer-keyboard-quit)
(key-chord-define minibuffer-local-must-match-map "jk" 'minibuffer-keyboard-quit)
(key-chord-define minibuffer-local-isearch-map "jk" 'minibuffer-keyboard-quit)
I have do some hack with isearch to reproduce the jk magic.
(defun isearch-enable-key-chord ()
(key-chord-mode 1)
(key-chord-define isearch-mode-map "jk" 'isearch-cancel))
(add-hook 'isearch-mode-hook 'isearch-enable-key-chord)
(with-eval-after-load 'evil
(key-chord-define evil-insert-state-map "jj" #'evil-normal-state))
(defun company-abort-and-evil-normal-mode ()
(interactive)
(company-abort)
(when (evil-insert-state-p)
(evil-normal-state)))
(with-eval-after-load 'company
(key-chord-define company-active-map "jj"
#'company-abort-and-evil-normal-mode)
(define-key company-active-map [escape]
#'company-abort-and-evil-normal-mode))
(key-chord-define-global "mx" #'helm-M-x)
(key-chord-define-global "mm" 'ace-window)
(with-eval-after-load 'popup
(define-key popup-menu-keymap (kbd "M-n") 'popup-next)
(define-key popup-menu-keymap (kbd "TAB") 'popup-next)
(define-key popup-menu-keymap (kbd "<tab>") 'popup-next)
(define-key popup-menu-keymap (kbd "<backtab>") 'popup-previous)
(define-key popup-menu-keymap (kbd "M-p") 'popup-previous))
It’s too difficult to combine hungry delete mode
, evil mode
and electric
pair mode
. So share M-DEL
between hungry-delete-backward and
backward-kill-word. If there are more than one spaces, run
hungry-delete-backward; otherwise run backward-kill-word.
(setq hungry-delete-chars-to-skip " \t")
(defun backward-kill-word-or-hungry-delete ()
(interactive)
(if (looking-back "[ \t\n\r\f\v]\\{2,\\}")
(call-interactively 'hungry-delete-backward)
(call-interactively 'backward-kill-word)))
(define-key global-map (kbd "M-DEL") 'backward-kill-word-or-hungry-delete)
In Emacs-24.4, electric-indent-mode works well with f90-mode and
python-mode. It will not mesh your indentation anymore. With electric indent
mode
on, just type RET
and the current line and the newline will be
indented. You don’t have to rebind RET
to newline-and-indent.
(electric-indent-mode 1)
(setq avy-all-windows nil)
Ace window is superior to window numbering for that window numbering shows number in the mode line which is not friendly to my eyes.
(defun ace-window-dwim (&optional arg)
(interactive "P")
(cond
((equal arg '(4))
(call-interactively 'ace-delete-window))
((equal arg '(16))
(call-interactively 'ace-maximize-window))
(t
(call-interactively 'ace-window))))
(setq aw-keys '(?a ?s ?d ?f ?g ?h ?j ?k ?l))
(global-set-key (kbd "C-x o") #'ace-window-dwim)
I can’t connect the number with the direction of window splitting.
(global-set-key (kbd "C-x -") #'split-window-below)
(global-set-key (kbd "C-x \\") #'split-window-right)
Just press SPC-w
, the first character of word where you want to go and select
the pop up character, you can move in Emacs quickly. Press C-x SPE to jump
back.
(let ((key "o"))
(eval-after-load "info"
`(define-key Info-mode-map ,key 'ace-link-info))
(eval-after-load "compile"
`(define-key compilation-mode-map ,key 'ace-link-compilation))
(eval-after-load "help-mode"
`(define-key help-mode-map ,key 'ace-link-help))
(eval-after-load "eww"
`(progn
(define-key eww-link-keymap ,key 'ace-link-eww)
(define-key eww-mode-map ,key 'ace-link-eww)))
(eval-after-load 'cus-edit
`(progn
(define-key custom-mode-map ,key 'ace-link-custom))))
Ace jump is set in Normal state map and Isearch and ace jump.
(custom-set-faces
'(avy-lead-face-0 ((t (:background "color-20" :foreground "white")))))
(with-defhydra-evil-leader
"hydra-evil-leader-multiple-cursors"
"mc"
("n" mc/mark-next-like-this "next")
("p" mc/mark-previous-like-this "previous")
("a" mc/mark-all-like-this "all")
("l" mc/edit-lines "lines")
("q" nil "quit"))
(global-set-key (kbd "C-x C-b") 'ibuffer)