Skip to content

Instantly share code, notes, and snippets.

@jidaikobo-shibata
Last active July 11, 2016 13:34
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 jidaikobo-shibata/604173d11ff376036635fd4811df6abb to your computer and use it in GitHub Desktop.
Save jidaikobo-shibata/604173d11ff376036635fd4811df6abb to your computer and use it in GitHub Desktop.
Emacs(Elisp): To integrate indent style, delete existing whitespaces before indent-for-tab-command. indent-for-tab-commandの前に存在する行頭ホワイトスペースを削除することでインデントスタイルを統一する
;; defadvice-indent-for-tab-command
;; gist-description: Emacs(Elisp): To integrate indent style, delete existing whitespaces before indent-for-tab-command. indent-for-tab-commandの前に存在する行頭ホワイトスペースを削除することでインデントスタイルを統一する
;; gist-id: 604173d11ff376036635fd4811df6abb
;; gist-name: defadvice-indent-for-tab-command.el
;; gist-private: nil
(defadvice indent-for-tab-command (around advise-indent-for-tab-command activate)
"To integrate indent style, delete existing whitespaces before indentation."
(let (beg
end
(end-line nil))
(cond
((use-region-p)
(setq beg (region-beginning)
end (region-end)
end-line (line-number-at-pos end)))
(t
(beginning-of-line)
(setq beg (point))
(end-of-line)
(setq end (point))))
(perform-replace "^[\t ]+" "" nil t nil nil nil beg end)
(goto-char beg)
(set-mark-command nil)
(goto-char end)
ad-do-it
(when end-line (goto-line (- end-line 1))) ;; why should i have to do minus?
(back-to-indentation)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment