Skip to content

Instantly share code, notes, and snippets.

@thiagoa
Forked from WaYdotNET/align.el
Created July 6, 2018 04:05
Show Gist options
  • Save thiagoa/7d564b093f40db98cbcb4571c790a5dc to your computer and use it in GitHub Desktop.
Save thiagoa/7d564b093f40db98cbcb4571c790a5dc to your computer and use it in GitHub Desktop.
Align function emacs
;; 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 ))
# 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