1/28/2021

Emacs comment/uncomment region

After setting,

Select the coding block 

Then use

Ctrl C then Ctrl - 

to comment and uncomment the block of the code.

http://ergoemacs.org/emacs/keyboard_shortcuts.html

(global-set-key (kbd "M-a") 'backward-char) ; Alt+a

(global-set-key (kbd "C-a") 'backward-char) ; Ctrl+a

(global-set-key (kbd "C-c t") 'backward-char) ; Ctrl+c t

(global-set-key (kbd "<f7> <f8>") 'whitespace-mode)    ; F7 F8
 
 (custom-set-variables
;; custom-set-variables was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.
;; If there is more than one, they won't work right.
'(custom-enabled-themes (quote (tango)))
'(inhibit-startup-screen t))
(custom-set-faces
;; custom-set-faces was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.
;; If there is more than one, they won't work right.
'(default ((t (:family "DejaVu Sans Mono" :foundry "unknown" :slant normal :weight normal :height 120 :width normal)))))
(set-default-font "14")
(global-linum-mode t)

(defun comment-or-uncomment-region-or-line ()
"Comments or uncomments the region or the current line if there's no active region."
(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)))

(global-set-key (kbd "C-c C--") 'comment-or-uncomment-region-or-line)


没有评论: