-
Notifications
You must be signed in to change notification settings - Fork 0
/
doqmnt.el
151 lines (121 loc) · 4.32 KB
/
doqmnt.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
;;; doqmnt.el --- A library for automatic documentation of code. -*- lexical-binding: t; -*-
;; Copyright (C) 2021 Joshua T. Guerin & Kathleen Ericson
;; Author: Joshua T. Guerin, Ph.D. <[email protected]>
;; Maintainer: Kathleen Ericson, Ph.D. <[email protected]>
;; Created: 02 August 2021
;; Keywords: languages programming documentation comments
;; URL: https://github.com/joshuaguerin/doqmnt
;; This file is not part of GNU Emacs.
;; This file is free software. You are welcome to download it and give it a try!
;; Please note that no guarantees are made regarding software correctness.
;; Please feel free to give the source a read to make yourself comfortable with how it works.
;; We are not responsible for anything that may go wrong in running the software.
;; (Although we do not currently foresee anything that it would do.)
;; Package-Requirements: N/A
;;; Code:
(defun file-doq ()
"Insert a header comment at the top of the file."
(interactive)
(setq current (point))
(setq total (point-max))
(goto-char 0)
(insert "/**\n * @file ")
(setq vals (split-string (buffer-file-name) "/"))
(insert (car (last vals))) ; need to fix
(insert "\n * @author ")
(insert user-full-name)
(insert "\n * @date ")
(insert (shell-command-to-string "echo -n $(date +%Y-%m-%d)"))
(insert (concat' "\n * @brief " (read-string "@brief ")))
(insert "\n * \n * ")
(insert (read-string "@description "))
(insert "\n */\n\n")
(setq total (- (point-max) total))
(setq current (+ current total))
(goto-char current))
(defun class-doq ()
"Provide documentation for the class declared on the current line."
(interactive)
(setq current (point))
(setq p1 (line-beginning-position))
(end-of-line)
(setq p2 (point))
(setq line (buffer-substring p1 p2))
(setq def (split-string line))
(setq classname (cadr def))
(setq end (point-max))
(goto-char p1)
(insert "\n/**\n")
(insert (concat' " * " (read-string "@description: ") "\n"))
(insert " *\n * @class ")
(insert classname)
(insert " ")
(setq vals (reverse (split-string (buffer-file-name) "/")))
(insert (car vals)) ; need to fix
(insert " \"")
(insert (cadr vals))
(insert "/")
(insert (car vals))
(insert "\"\n")
;;(insert " * @brief ")
(setq brief (concat' " * @brief " (read-string "@brief: ")))
(insert brief)
(insert "\n *\n */\n")
(setq end (- (point-max) end))
(goto-char (+ current end)))
(defun fun-doq ()
"Insert a comment above the prototype on the current line."
(interactive)
(setq end (point-max))
(setq p1 (line-beginning-position))
(setq position (point))
(end-of-line)
(setq p2 (point))
;; Retrieve prototype line
(setq line (buffer-substring p1 p2))
(goto-char p1)
;; Process prototype
(setq arglist (get_args line))
(setq type_name (get_type_ident line))
;; Start docs
(insert "\n/**\n")
(insert (concat' " * " (read-string "@description ") "\n *\n"))
;; Process args if they exist
(insert_args? arglist)
(insert (concat' " * @pre " (read-string "@pre ") "\n"))
;; Process type info if it exists
(insert_type? type_name)
(insert (concat' " * @post " (read-string "@post ") "\n"))
(insert " * \n */\n")
;; Return to original cursor position.
(goto-char (+ position (- (point-max) end))))
;; String Processing Functions ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Takes prototype, returns a list containing a type and identifier
(defun get_ty