Skip to content

Instantly share code, notes, and snippets.

@c02y
Last active March 8, 2019 10:43
Show Gist options
  • Save c02y/77187110f0259562f3ea868fb6d77a27 to your computer and use it in GitHub Desktop.
Save c02y/77187110f0259562f3ea868fb6d77a27 to your computer and use it in GitHub Desktop.
fold in emacs
delete origami config(and other func mentioned origami) and package since it doesn't work well with Python
delete iy-go-to-char config and package
C-return binding doesn't work with Emacs in terminal, so rebind
;; yafolding
;; (autoload 'yafolding "yafolding" t)
(add-hook 'prog-mode-hook 'yafolding-mode)
(bind-keys :map prog-mode-map
("C-c f" . yafolding-toggle-element)
("C-c F" . yafolding-toggle-all))
add
(highlight-indent-guides-mode . "")
(electric-operator-mode . "")
(defun cleanup-buffer ()
"Cleanup the buffer:
1. yafolding-show-all to avoid date loss
2. delete-trailing-whitespace
"
(interactive)
(yafolding-show-all) ;; avoid data loss
(delete-trailing-whitespace))
remove bbyac/browser-kill-ring config and package
remove ~/.emacs.d/.mc-lists.el file, this will cause promot "for all cursors"
add this in comment around multiple-cursors
(bind-key* "C-c C-c"
(defhydra hydra-change-case (:hint nil)
""
("c" endless/capitalize "capitalize")
("l" endless/downcase "downcase")
("u" endless/upcase "upcase")
("z" undo-tree-undo "undo")
("Z" undo-tree-redo "redo")
("q" nil)))
delete old resize window bindings
(bind-key* "C-x @"
(defhydra hydra-resize-window (:hint nil)
""
("<left>" shrink-window-horizontally "-narrower-")
("<right>" enlarge-window-horizontally "-wider-")
("<down>" shrink-window "|shorter|")
("<up>" enlarge-window "|taller|")
("q" nil)))
(autoload 'multiple-cursors "multiple-cursors" t)
(bind-key* "C-c m"
(defhydra hydra-multiple-cursors (:hint nil)
"
^Up^ ^Down^ ^Other^
----------------------------------------------
[_p_] Prev [_n_] Next [_l_] Edit lines
[_P_] Skip_P [_N_] Skip_N [_a_] Mark all
[_M-p_] Unmark_P [_M-n_] Unmark_N [_r_] Mark by regexp
[_z_] Undo [_Z_] Redo [_q_] Quit
"
("l" mc/edit-lines :exit t)
("a" mc/mark-all-like-this :exit t)
("n" mc/mark-next-like-this)
("N" mc/skip-to-next-like-this)
("M-n" mc/unmark-next-like-this)
("p" mc/mark-previous-like-this)
("P" mc/skip-to-previous-like-this)
("M-p" mc/unmark-previous-like-this)
("r" mc/mark-all-in-region-regexp :exit t)
("z" undo-tree-undo)
("Z" undo-tree-redo)
("q" nil)))
delete flycheck defhydra part, it is useless
clean wrong usage of bind-key* and bind-keys*
(bind-key* "C-x M-z" (lambda () (interactive) (switch-to-buffer "*scratch*")))
(bind-key* "C-x M-p"
(lambda ()
(interactive)
(if (bound-and-true-p which-function-mode)
(which-function-mode -1)
(which-function-mode 1))
(if (bound-and-true-p projectile-global-mode)
(projectile-global-mode -1)
(projectile-global-mode 1))))
(bind-key* "C-x C-s"
(lambda ()
(interactive)
(progn
;; check if the buffer is a file or like *scratch*
(if (buffer-file-name)
(if (file-writable-p buffer-file-name) (save-buffer)
(write-file (concat "/sudo::" buffer-file-name)))
(save-buffer)))))
(bind-key* "C-c #"
(defhydra change-num-in-region (:hint nil)
""
("<up>" increment-region "increment")
("<down>" decrement-region "decrement")
("q" nil)))
to replace
bin-keys for increment/decrement-region
(bind-key* "C-M-q"
(lambda ()
(interactive)
(delete-indentation 1)))
(bind-key* "M-q" 'xah-fill-or-unfill)
(bind-key* "C-x #"
(defhydra hydra-rectangle
(:body-pre (rectangle-mark-mode 1)
:color pink
:hint nil
:post (deactivate-mark))
"
^_k_^ _w_ copy _o_pen _N_umber-lines |\\ -,,,--,,_
_h_ _l_ _y_ank _t_ype _e_xchange-point /,`.-'`' .. \-;;,_
^_j_^ _d_ kill _c_lear _r_eset-region-mark |,4- ) )_ .;.( `'-'
^^^^ _u_ndo _g_ quit ^ ^ '---''(./..)-'(_\_)
"
("k" rectangle-previous-line)
("j" rectangle-next-line)
("h" rectangle-backward-char)
("l" rectangle-forward-char)
("d" kill-rectangle) ;; C-x r k
("y" yank-rectangle) ;; C-x r y
("w" copy-rectangle-as-kill) ;; C-x r M-w
("o" open-rectangle) ;; C-x r o
("t" string-rectangle) ;; C-x r t
("c" clear-rectangle) ;; C-x r c
("e" rectangle-exchange-point-and-mark) ;; C-x C-x
("N" rectangle-number-lines) ;; C-x r N
("r" (if (region-active-p)
(deactivate-mark)
(rectangle-mark-mode 1)))
("u" undo nil)
("g" nil)))
(add-hook 'sh-mode-hook
(lambda ()
(setq indent-tabs-mode nil)))
(bind-keys*
("C-w" . delete-line-or-region-or-buffer)
;; ("M-w" . copy-line-or-region-or-buffer) ; replace it with easy-kill
("C-x w" . cut-line-or-region-or-buffer))
;; C-u C-w/M-w/C-x w to delete/copy/cut whole buffer without moving point
(defun current-line-empty-p ()
(save-excursion
(beginning-of-line)
(looking-at "[[:space:]]*$")))
(defun delete-line-or-region-or-buffer ()
"Delete current line, or text selection.
When `universal-argument' is called first, delete whole buffer (respects `narrow-to-region')."
(interactive)
(if current-prefix-arg
(delete-region (point-min) (point-max))
(progn (if (use-region-p)
(delete-region (region-beginning) (region-end))
(progn
(if (current-line-empty-p)
(delete-blank-lines)
(delete-region (line-beginning-position) (line-end-position)))))
;; delete the extra empty line
(delete-char 1)
(indent-for-tab-command))))
(defun copy-line-or-region-or-buffer ()
"Copy current line, or text selection.
When called repeatedly, append copy subsequent lines.
When `universal-argument' is called first, copy whole buffer (respects `narrow-to-region').
URL `http://ergoemacs.org/emacs/emacs_copy_cut_current_line.html'
Version 2016-06-18"
(interactive)
(let (-p1 -p2)
(if current-prefix-arg
(setq -p1 (point-min) -p2 (point-max))
(if (use-region-p)
(setq -p1 (region-beginning) -p2 (region-end))
;; (setq -p1 (line-beginning-position) -p2 (line-end-position))))
;; use non-white position
;; -p1 is the position of beginning of line of non-whitespace
;; -p2 is the position of end of line of non-whitespace
(setq -p1 (save-excursion (back-to-indentation) (point))
-p2 (save-excursion
(end-of-line)
(skip-syntax-backward "-")
(point)))))
(if (eq last-command this-command)
(progn
(progn ; hack. exit if there's no more next line
(end-of-line)
(forward-char)
(backward-char))
;; (push-mark (point) "NOMSG" "ACTIVATE")
(kill-append "\n" nil)
(kill-append (buffer-substring-no-properties (line-beginning-position) (line-end-position)) nil)
(message "Line copy appended"))
(progn
(kill-ring-save -p1 -p2)
(if current-prefix-arg
(message "Buffer text copied")
(message "Text copied"))))
;; (end-of-line)
;; (forward-char)
))
(defun cut-line-or-region-or-buffer ()
"Cut current line, or text selection.
When `universal-argument' is called first, cut whole buffer (respects `narrow-to-region').
URL `http://ergoemacs.org/emacs/emacs_copy_cut_current_line.html'
Version 2015-06-10"
(interactive)
(if current-prefix-arg
(progn ; not using kill-region because we don't want to include previous kill
(kill-new (buffer-string))
(delete-region (point-min) (point-max)))
(progn (if (use-region-p)
(kill-region (region-beginning) (region-end) t)
(progn
(if (current-line-empty-p)
(delete-blank-lines)
;; (kill-region (line-beginning-position) (line-end-position))
;; use non-white position
(kill-region
(save-excursion (back-to-indentation) (point))
(save-excursion
(end-of-line)
(skip-syntax-backward "-")
(point))))))
;; delete the no-whitespace part in this line
(when (current-line-empty-p) (delete-blank-lines))
;; delete the extra empty line
(delete-char 1)
(indent-for-tab-command))))
(bind-keys*
("C-w" . delete-line-or-region-or-buffer)
("M-w" . copy-line-or-region-or-buffer) ; replace it with easy-kill
("C-x w" . cut-line-or-region-or-buffer))
;; easy-kill
;; M-d and more keys, ? for help, C-M-@ for easy-mark
;; Note, -/+ doesn't not mark but select, use C-SPC to mark the selection again
;; then do delete/C-w/C-x w on the marked part
(require 'easy-kill)
(global-set-key [remap kill-ring-save] 'easy-kill)
(global-set-key [remap mark-sexp] 'easy-mark) ; C-M-@
(bind-key* "C-x M-w" 'easy-kill)
;; NOTE: remember to C-M-\ (indent-region) to reindent the code(block) after yanking
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment