aboutsummaryrefslogtreecommitdiffstats
path: root/emacs/.emacs.d
diff options
context:
space:
mode:
authorGravatar Tom Willemse2016-10-07 01:24:02 +0200
committerGravatar Tom Willemse2016-10-07 01:24:02 +0200
commite878b5896752f5702134a27325ecc442af7aaf67 (patch)
tree14690037013d573ec7be62db4f82dedf30cce888 /emacs/.emacs.d
parent6b7b0aec5f201d8bfd1006f928ceb01b4f6fd566 (diff)
downloadnew-dotfiles-e878b5896752f5702134a27325ecc442af7aaf67.tar.gz
new-dotfiles-e878b5896752f5702134a27325ecc442af7aaf67.zip
Add automatic alignment rules for CSS and PHP code
Diffstat (limited to 'emacs/.emacs.d')
-rw-r--r--emacs/.emacs.d/init.org84
1 files changed, 84 insertions, 0 deletions
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
+ <?php
+ array(
+ 'foo' => '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.