diff --git a/emacs/.emacs.d/init.org b/emacs/.emacs.d/init.org index e780766..4450179 100644 --- a/emacs/.emacs.d/init.org +++ b/emacs/.emacs.d/init.org @@ -398,6 +398,90 @@ To start off, first I need to enable lexical binding. user-mail-address "tom@ryuslash.org") #+END_SRC +* Automatic alignment + + Emacs has some powerful automatic alignment features. + + #+BEGIN_SRC emacs-lisp + (eval-when-compile (require 'align)) + #+END_SRC + +** CSS + + Align CSS files like so: + + #+BEGIN_SRC css + body { color: #ffffff; } + .some-class { background-color: #ffffff; } + #some-id { width: 200px; } + + .some-more-class { + color: #ffffff; + background-color: #ffffff; + width: 200px; + } + #+END_SRC + + #+BEGIN_SRC emacs-lisp + (with-eval-after-load 'align + ;; Keep these in order. They are each added to the _front_ of the + ;; list and are applied in order. Changing their order will change + ;; the results. + (add-to-list 'align-rules-list + `(css-closing-brace + (regexp . ,(rx (group (0+ whitespace)) "}" eol)) + (group . (1)) + (modes . '(scss-mode css-mode)))) + (add-to-list 'align-rules-list + `(css-colons + (regexp . ,(rx bol + (0+ whitespace) + (1+ (any (?a . ?z) ?- ?$)) + ":" + (group (0+ whitespace)) + (0+ nonl) + ";" + eol)) + (group . (1)) + (modes . '(scss-mode css-mode)) + (repeat . t))) + (add-to-list 'align-rules-list + `(css-opening-brace + (regexp . ,(rx bol + (0+ whitespace) + (0+ (any ?# ?. ?, ?\s ?& ?: ?- + (?a . ?z) (?A . ?Z) (?0 . ?9))) + (any (?a . ?z) (?A . ?Z) (?0 . ?9)) + (group (0+ whitespace)) + "{" + (0+ nonl))) + (group . (1)) + (modes . '(scss-mode css-mode))))) + #+END_SRC + +** PHP + + In PHP code it's nice to have any ~=>~ aligned. + + #+BEGIN_SRC php + 'bar', + 'frob' => 'baz' + ); + ?> + #+END_SRC + + #+BEGIN_SRC emacs-lisp + (with-eval-after-load 'align + (add-to-list 'align-rules-list + `(php-array-arrow + (regexp . ,(rx any (group whitespace) "=>" any)) + (group . (1)) + (modes . '(php-mode web-mode)) + (repeat . t)))) + #+END_SRC + * Url browsing Use Conkeror to open URLs.