summaryrefslogtreecommitdiff
path: root/templates/snippets/doxygen/doxycomments
blob: 94209bc651ec3b0b5969604c968c20f1f0100163 (plain)
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
# -*- mode: snippet -*-
# name: doxcomments
# key: dox
# type: command
# --
;; Command to generate doxygen comments for c functions

(defun flatten (ls)
  "Implements standard flatten function"
  (cond
   ((atom ls) (list ls))
   ((null (cdr ls)) (flatten (car ls)))
   (t (append (flatten (car ls)) (flatten (cdr ls))))))

(defun find-retval ()
  "Returns the return value of the next parsed function"
  (interactive)
  (let ((struct-type "struct"))
    (search-forward "(" nil t)
    (move-beginning-of-line nil)
    (let ((return-type (thing-at-point 'symbol)))
      (if (string= return-type struct-type)
	  "NOT_IMPLEMENTED"
	return-type))))

(defun find-args ()
  "Returns a list of function args for the next parsed function"
  (interactive)
  (let* ((struct-type "struct")
	 (start (search-forward "(" nil t))
	 (end (search-forward ")" nil t))
	 (args-string (buffer-substring-no-properties start (1- end)))
	 (args (mapcar 'string-trim-left (split-string args-string "," t))))
    (mapcar (lambda (x) (car (reverse x))) (mapcar 'split-string args))))

(let* ((retval (find-retval))
       (args (find-args))
       (args-len (length args))
       (brief  "@brief $1\n *")
       (params (mapcar (lambda (x) (format "@param: %s ${%d:}" (cdr x) (car x)))
		       (mapcar* 'cons
				(mapcar '1+ (number-sequence 1 args-len))
				args)))
       (retval (format "@return %s $0" retval))
       (snippet-text (mapconcat 'identity (flatten (list "/**" brief params (concat "\n * " retval)))
				"\n * ")))
  (move-beginning-of-line nil)
  (yas-expand-snippet (concat snippet-text "\n*/\n")))