add doc-comment

This commit is contained in:
zongor 2024-11-25 14:03:40 -05:00
parent 670bf2781b
commit aa1dec6d9e
1 changed files with 28 additions and 0 deletions

28
.emacs
View File

@ -117,6 +117,33 @@
(point)))) (point))))
(comment-or-uncomment-region start end))) (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 (use-package evil
:ensure t :ensure t
:init :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-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-u") 'eval-buffer)
(define-key evil-normal-state-map (kbd "C-M-p") 'compile) (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 "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-previous-window)
(define-key evil-normal-state-map (kbd "C-.") 'move-to-next-window) (define-key evil-normal-state-map (kbd "C-.") 'move-to-next-window)