From 11b4a3502a42c36ecbb5ab6f6b88ed47f85a5830 Mon Sep 17 00:00:00 2001 From: Sean Farley Date: Mon, 28 Jan 2019 15:14:09 -0800 Subject: [PATCH] bindings: add common comment toggle This is fairly common in most editors so let's make lives easier. --- core/autoload/editor.el | 10 ++++++++++ modules/config/default/config.el | 1 + 2 files changed, 11 insertions(+) diff --git a/core/autoload/editor.el b/core/autoload/editor.el index 5c896b702..45335b37a 100644 --- a/core/autoload/editor.el +++ b/core/autoload/editor.el @@ -270,6 +270,16 @@ Respects `require-final-newline'." (when (looking-at "\n+") (replace-match ""))) +;;;###autoload +(defun doom/toggle-comment-region-or-line () + "Comments or uncomments the whole region or if no region is +selected, then the current line." + (interactive) + (let (beg end) + (if (region-active-p) + (setq beg (region-beginning) end (region-end)) + (setq beg (line-beginning-position) end (line-end-position))) + (comment-or-uncomment-region beg end))) ;; ;; Advice diff --git a/modules/config/default/config.el b/modules/config/default/config.el index 03a99e17a..eb3446fc1 100644 --- a/modules/config/default/config.el +++ b/modules/config/default/config.el @@ -156,6 +156,7 @@ "s--" #'text-scale-decrease ;; Conventional text-editing keys & motions "s-a" #'mark-whole-buffer + "s-/" #'doom/toggle-comment-region-or-line :gi [s-return] #'+default/newline-below :gi [s-S-return] #'+default/newline-above :gi [s-backspace] #'doom/backward-kill-to-bol-and-indent