Created
November 15, 2010 14:40
-
-
Save WaYdotNET/700416 to your computer and use it in GitHub Desktop.
Align function emacs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; Align command !!! | |
;; from http://stackoverflow.com/questions/3633120/emacs-hotkey-to-align-equal-signs | |
;; another information: https://gist.github.com/700416 | |
;; use rx function http://www.emacswiki.org/emacs/rx | |
(defun align-to-colon (begin end) | |
"Align region to colon (:) signs" | |
(interactive "r") | |
(align-regexp begin end | |
(rx (group (zero-or-more (syntax whitespace))) ":") 1 1 )) | |
(defun align-to-comma (begin end) | |
"Align region to comma signs" | |
(interactive "r") | |
(align-regexp begin end | |
(rx "," (group (zero-or-more (syntax whitespace))) ) 1 1 )) | |
(defun align-to-equals (begin end) | |
"Align region to equal signs" | |
(interactive "r") | |
(align-regexp begin end | |
(rx (group (zero-or-more (syntax whitespace))) "=") 1 1 )) | |
(defun align-to-hash (begin end) | |
"Align region to hash ( => ) signs" | |
(interactive "r") | |
(align-regexp begin end | |
(rx (group (zero-or-more (syntax whitespace))) "=>") 1 1 )) | |
;; work with this | |
(defun align-to-comma-before (begin end) | |
"Align region to equal signs" | |
(interactive "r") | |
(align-regexp begin end | |
(rx (group (zero-or-more (syntax whitespace))) ",") 1 1 )) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Ruby example | |
# FROM: | |
class Demo | |
property :id, Ciao | |
property :demo, String | |
property :foo, Bar | |
end | |
# align-to-comma: | |
class Demo | |
property :id, Ciao | |
property :demo, String | |
property :foo, Bar | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The align to colon wasn't working quite right for ruby hashes like this:
Here is a modification that seems to work better: