Created Thursday 28 November 2013

  1. Site:
    1. http://www.gnu.org/software/emacs/
  2. Emacs Wiki:
    1. http://www.emacswiki.org/
  3. Emacs Rocks:
    1. http://emacsrocks.com/
  4. Essential tips:
    1. http://web.psung.name/emacstips/essential.html

  1. Emacs replace rectangle contents:
    1. C-x r t string <RET>
  2. Emacs replace-regex with backreference:
    1. http://www.gnu.org/software/emacs/manual/html_node/emacs/Regexp-Replace.html
In replace-regexp, the newstring need not be constant: it can refer to all or part of what is matched by the regexp. ‘\&’ in newstring stands for the entire match being replaced. ‘\d’ in newstring, where d is a digit, stands for whatever matched the dth parenthesized grouping in regexp. (This is called a “back reference”.) ‘\#’ refers to the count of replacements already made in this command, as a decimal number. In the first replacement, ‘\#’ stands for ‘0’; in the second, for ‘1’; and so on. For example,

M-x replace-regexp <RET> c[ad]+r <RET> \&-safe <RET>

replaces (for example) ‘cadr’ with ‘cadr-safe’ and ‘cddr’ with ‘cddr-safe’.

M-x replace-regexp <RET> \(c[ad]+r\)-safe <RET> \1 <RET>

performs the inverse transformation. To include a ‘\’ in the text to replace with, you must enter ‘\\’.

If you want to enter part of the replacement string by hand each time, use ‘\?’ in the replacement string. Each replacement will ask you to edit the replacement string in the minibuffer, putting point where the ‘\?’ was.
C-M-s \(^.*\)\(linear-gradient(\)to \b\w*\b\(.*$\) - just to be sure that the selection works
C-M-% \(^.*\)\(linear-gradient(\)to \b\w*\b\(.*$\) <RET>
\& C-q C-j
(use anything-query-replace-regexp for dynamic highlighting)
EXAMPLE 2 (perfection)
C-M-% \(^.*\)\(linear-gradient(\)\(to right\|to bottom\)\(.*$\) <RET>
\& C-q C-j
\1-prefix-\2\,(if (equal "to right" \3) "left" "top")\4
  1. Emacs regex to replace existing radiuses with 5 px:
    1. C-M-% \(border-radius:\)\( ?\)\([0-9]+px\|0\)\( ?\)\([0-9]+px\|0\)\( ?\)\([0-9]+px\|0\)\( ?\)\([0-9]+px\|0\) <RET>

\1\2\,(if (not (equal "0" \3)) "5px" "0")\4\,(if (not (equal "0" \5)) "5px" "0")\6\,(if (not (equal "0" \7)) "5px" "0")\8\,(if (not (equal "0" \9)) "5px" "0")
  1. Emacs html-mode jump to closing/opening tag:
    1. C-c C-f
C-c C-b
  1. Emacs delete matching lines:
    1. M-x delete-matching-lines - an alias for flush-lines
  2. Emacs regex multiple lines:
    1. http://www.emacswiki.org/emacs/MultilineRegexp
For incremental search use C-q C-j
^.*background.*:linear.*^J.*^J.*^J.*^J.*$ - ^J states for C-q C-j
\(^.*background.*:linear.*^J\)\(.*^J\)\(.*^J\)\(.*^J\)\(.*$\) - OR:
  1. Emacs 5 space delimited columns regex:
    1. ^\([^ ]* \)\{5\}
  2. Emacs regex find '.' then numbers and ' ' and everything till ' ':
    1. \.[0-9]* [^ ]*
  3. Setting default theme in Emacs:
    1. Open .emacs.d/init.el or .emacs
    2. Add:
      1. (load-theme 'manoj-dark)
  4. Emacs Prelude (and classic emacs):
    1. Disable flyspell:
      1. Add to init.el (or .emacs):
        1. (setq prelude-flyspell nil)
    2. Disable tabs indentation:
      1. (setq-default indent-tabs-mode nil)
      2. http://emacsblog.org/2007/09/30/quick-tip-spaces-instead-of-tabs/
    3. Disable whitespace highlighting:
      1. https://github.com/bbatsov/prelude/issues/52
        1. Redefine prelude-prog-mode-hook:
(defun prelude-prog-mode-hook ()
"Default coding hook, useful with any programming language."
(linum-mode +1)
;; keep the whitespace decent all the time
(add-hook 'before-save-hook 'whitespace-cleanup nil t))
      1. (setq prelude-whitespace nil)
  1. Highlight more than 80 columns:
    1. Edit core/prelude-editor.el:
      1. (setq whitespace-line-column 80)
  1. Set default path:
    1. http://superuser.com/questions/249525/how-to-change-the-default-directory-in-emacs
  2. Navigate to previous position:
    1. C-u C-<SPC>
    2. http://web.psung.name/emacstips/essential.html
  3. Auto-numerate lines:
    1. Put (global-linum-mode 1) in .emacs
    2. http://stackoverflow.com/questions/8154271/how-to-auto-run-the-m-x-linum-mode-to-display-line-number
  4. Show full path for the current buffer:
    1. M-: (buffer-file-name) RET
    2. http://lists.gnu.org/archive/html/help-gnu-emacs/2007-04/msg00390.html
  5. Change file EOL (end of line):
    1. M-x set-buffer-file-coding-system utf-8-unix (for LF)
    2. M-x set-buffer-file-coding-system utf-8-mac (for CR)
    3. M-x set-buffer-file-coding-system utf-8-dos (for CR+LF)
    4. http://www.emacswiki.org/emacs/EndOfLineTips
  6. Revert buffer with custom encoding:
    1. http://stackoverflow.com/questions/8627432/emacs-opening-and-saving-encoding
      1. M-x revert-buffer-with-coding-system
      2. iso-8859-8