- Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhelpers.el
41 lines (39 loc) · 1.44 KB
/
helpers.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
;; Emacs utility functions for php-git2
(defunphp-git2-make-constants ()
"Translate C-language strings into php-git2 constant macro expressions"
(interactivenil)
(let ((case-fold-searchnil)
(text (buffer-substring-no-properties (region-beginning) (region-end)))
(pos 0)
(result ""))
(while (string-match"\\(GIT_[A-Z0-9_]+\\)" text pos)
(setq result (concat result (concat
"PHP_GIT2_CONSTANT("
(concat
(match-string1 text)
");\n"))))
(setq pos (match-end0))
)
(delete-region (region-beginning) (region-end))
(insert result)
)
)
(defunphp-git2-make-funcargs ()
"Translate line-oriented function args from doc webpage into template args"
(interactivenil)
(let ((text (buffer-substring-no-properties (region-beginning) (region-end)))
(pos 0)
(result "int,\n"))
(while (string-match"\\(const\\)? *\\([^][ *]+\\) *\\([*]+\\|[[][]]\\)?.*\n*" text pos)
(if (match-string1 text)
(setq result (concat result "const ")))
(setq result (concat result (match-string2 text)))
(if (match-string3 text)
(setq result (concat result (match-string3 text))))
(setq result (concat result ",\n"))
(setq pos (match-end0))
)
(delete-region (region-beginning) (region-end))
(insert (substring result 0 (- (length result) 2)))
)
)