Files
.emacs.d/modules/text-editing/siren-toggle-comments.el
Jim Myhrberg b0a7dad59b chore(text-editing): Enable terminal-specific comment toggling
Emacs in a terminal interprets `C-c C-/` as `C-c C-_`, so let's make it
behave like it does in GUI.
2020-03-21 22:55:33 +00:00

34 lines
1.2 KiB
EmacsLisp

;;; siren-toggle-comments.el --- jimeh's Emacs Siren: toggle-comments
;;; Commentary:
;; Allows to toggle comments for current line or selected region. Shamelessly
;; ripped from textmate.el: https://github.com/defunkt/textmate.el
;;; Code:
(defmacro allow-line-as-region-for-function (orig-function)
`(defun ,(intern (concat (symbol-name orig-function) "-or-line"))
()
,(format "Like `%s', but acts on the current line if mark is not active."
orig-function)
(interactive)
(if mark-active
(call-interactively (function ,orig-function))
(save-excursion
;; define a region (temporarily) -- so any C-u prefixes etc. are preserved.
(beginning-of-line)
(set-mark (point))
(end-of-line)
(call-interactively (function ,orig-function))))))
(unless (fboundp 'comment-or-uncomment-region-or-line)
(allow-line-as-region-for-function comment-or-uncomment-region))
(global-set-key (kbd "C-c /") 'comment-or-uncomment-region-or-line)
(global-set-key (kbd "C-c C-/") 'comment-or-uncomment-region-or-line)
(global-set-key (kbd "C-c C-_") 'comment-or-uncomment-region-or-line)
(provide 'siren-toggle-comments)
;;; siren-toggle-comments.el ends here