Skip to content

Instantly share code, notes, and snippets.

@c02y
Last active July 14, 2018 04:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save c02y/53f3dc97f2c985e89b86095d6a27a1c3 to your computer and use it in GitHub Desktop.
Save c02y/53f3dc97f2c985e89b86095d6a27a1c3 to your computer and use it in GitHub Desktop.
align comments and macro pf multiple lines
;; align-regexp with space instead tab
(defadvice align-regexp (around align-regexp-with-spaces activate)
(let ((indent-tabs-mode nil))
ad-do-it))
(defalias 'ar #'align-regexp)
(defadvice align (around align-with-spaces activate)
(let ((indent-tabs-mode nil))
ad-do-it))
(defun align-c-comments (beginning end)
"Align instances of // or /* */ within marked region."
(interactive "*r")
(let (indent-tabs-mode align-to-tab-stop)
(align-regexp beginning end "\\(\\s-*\\)[//|/*]")))
(defun align-c-macros (beginning end)
"Align macros within marked region"
(interactive "*r")
(progn
(align beginning end)
(untabify beginning end)))
(require 'cc-mode) ;; c-mode-map
(dolist (m (list c-mode-map c++-mode-map))
(bind-keys :map m
:prefix-map align-prefix-map
:prefix "C-c a"
("c" . align-c-comments)
("m" . align-c-macros)))
@c02y
Copy link
Author

c02y commented Jul 14, 2018

("a" . align)
("r" . align-regexp)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment