From aa1dec6d9e46875d09a600fe7c7fa645e03d2d08 Mon Sep 17 00:00:00 2001 From: zongor Date: Mon, 25 Nov 2024 14:03:40 -0500 Subject: [PATCH] add doc-comment --- .emacs | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/.emacs b/.emacs index b1a4746..74d38bb 100755 --- a/.emacs +++ b/.emacs @@ -117,6 +117,33 @@ (point)))) (comment-or-uncomment-region start end))) +(defun camel-case-to-spaces (string) + "Convert a camel-cased STRING to a string with spaces between words and capitalize only the first word." + (let* ((case-fold-search nil) ; Ensure case-sensitive matching + (words (split-string (replace-regexp-in-string "\\([a-z]\\)\\([A-Z]\\)" "\\1 \\2" string) " ")) + (first-word (car words)) + (rest-words (mapcar 'downcase (cdr words))) + (result (concat (capitalize first-word) " " (mapconcat 'identity rest-words " ")))) + result)) + +(defun doc-comment () + (interactive) + "Insert a CPP documentation comment, at the beginning of the current line +and position the cursor inside the comment. Additionally insert the word under the cursor since most of our comments are just the name of the function anyways." + (princ "doc-comment") + (let* ((bounds (bounds-of-thing-at-point 'word)) + (word (buffer-substring-no-properties (car bounds) (cdr bounds)))) + (beginning-of-line) + (open-line 1) + (indent-according-to-mode) + (let* ((indentation (current-column))) + (insert "/**\n") + (indent-to indentation) + (insert (concat " * " (camel-case-to-spaces word) ".\n")) + (indent-to indentation) + (insert " */") + (end-of-line 0)))) + (use-package evil :ensure t :init @@ -140,6 +167,7 @@ (define-key evil-normal-state-map (kbd "C-x l") 'list-buffers) (define-key evil-normal-state-map (kbd "C-M-u") 'eval-buffer) (define-key evil-normal-state-map (kbd "C-M-p") 'compile) + (define-key evil-normal-state-map (kbd "C-M-k") 'compile) (define-key evil-normal-state-map (kbd "M-/") 'dabbrev-expand) (define-key evil-normal-state-map (kbd "C-,") 'move-to-previous-window) (define-key evil-normal-state-map (kbd "C-.") 'move-to-next-window)