-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcustom-c-skel.el
165 lines (152 loc) · 6.1 KB
/
custom-c-skel.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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
;;; custom-c-skel.el --- Custom skeleton example. -*- lexical-binding: t; -*-
;; Created : Friday, August 28 2020.
;; Author : Pierre Rouleau <[email protected]>
;; Time-stamp: <2020-10-20 23:12:04, updated by Pierre Rouleau>
;;; ----------------------------------------------------------------------------
;;; Commentary:
;;
;; This is an example of a custom PEL compatible tempo skeleton that defines C
;; code features. Use this as a template for you own custom skeletons, using
;; the same function names. Store your file somewhere else and identify the
;; name of this file inside the corresponding PEL user option.
;;
;; defun name PEL user option
;; =================================== =================================
;; `pel-skels-c-function-def/custom' `pel-c-skel-function-define-style'
;;
;;
;; This uses the same facilities than the code inside pel-c-skels. The code
;; here can require any PEL .el file except pel_keys.el. It can also require
;; Emacs libraries. You have the full power of Emacs tempo skeletons and Emacs
;; Lisp.
;; Note: if you code depends on functions inside pel-skels-c.el or what it uses
;; you won't need to write require forms to load them. This is the case
;; in the example below, however, it's a good idea to do it anyway to
;; document your dependencies.
;; For other PEL files or other libraries you need to write a require
;; statement for them.
;; Put those statements inside the Dependencies section below or use lazy
;; require techniques written inside functions in a way similar to how PEL
;; code is written (look for require forms that pass the :noerror argument).
;; The header block skeleton below creates code that looks like this:
;; /* test-custom.c : Testing the skeleton.
;; **
;; ** U-FooBar restricted an and confidential. Copyright © U-FooBar 2020.
;; ** Created : Wednesday, September 9 2020.
;; ** Author : Pierre Rouleau <[email protected]>
;; ** Time-stamp: <2020-09-09 07:48:55, updated by Pierre Rouleau>
;; */
;; /* -------------------------------------------------------------------------- */
;; /* Module Description
;; ** ------------------
;; **
;; **
;; **
;; */
;;
;; /* -------------------------------------------------------------------------- */
;; /* Header Inclusion
;; ** ----------------
;; */
;;
;;
;;
;; /* -------------------------------------------------------------------------- */
;; /* Local Types
;; ** -----------
;; */
;;
;;
;;
;; /* -------------------------------------------------------------------------- */
;; /* Local Variables
;; ** ---------------
;; */
;;
;;
;;
;; /* -------------------------------------------------------------------------- */
;; /* Code
;; ** ----
;; */
;;
;;
;;
;; /* -------------------------------------------------------------------------- */
;; The function skeleton example below create code that looks like this:
;;
;; /* -------------------------------------------------------------------------- */
;; /* =========================
;; * list_registered_processes
;; * =========================
;; *
;; * Print or display the list of registered process on the specified device.
;; *
;; */
;;
;; void
;; list_registered_processes()
;; {
;;
;; }
;;; ----------------------------------------------------------------------------
;;; Dependencies:
;;
;;
(require 'pel--base) ; use: pel-when-text-in
(require 'pel-skels) ; use: pel-skel-....
(require 'pel-text-insert) ; use: pel-separator-line
(require 'pel-prompt) ; use: pel-prompt-...
(require 'pel-skels-c) ; use: pel-skels-c-function-def
;;; ----------------------------------------------------------------------------
;;; Code:
;;
(defun pel-skels-c-header-module-block/custom (fname is-a-header cmt-style)
"Example of a custom skeleton for the top of a C file.
The arguments are:
- FNAME := string. the name of the current file without path.
- IS-A-HEADER := boolean. non-nil if the file is a C header file, nil otherwise.
- CMT-STYLE := a list of 3 strings: (cb cc ce)
- cb : comment begin string
- cc : comment continuation string
- ce : comment end string."
(let ((purpose (pel-prompt-purpose-for "File" 'p))
(cb (nth 0 cmt-style))
(cc (nth 1 cmt-style))
(ce (nth 2 cmt-style)))
(list
'l
cb " " fname " : " purpose 'n
cc 'n
cc (format-time-string
" U-FooBar restricted an and confidential. Copyright © U-FooBar %Y.\n")
(pel-skel-created-comment cc)
(pel-skel-author-comment cc)
(pel-skel-time-stamp pel-c-skel-insert-file-timestamp cc)
ce (pel-when-text-in ce 'n)
(pel-separator-line) 'n)))
(defun pel-skels-c-function-def/custom ()
"Example of a custom skeleton function that defines a C function definition."
;; this let form creates and initializes the local variables
(let* ((fct-name (pel-prompt-function (function pel-valid-c-function-name)))
(purpose (pel-prompt-purpose-for "Function" 'p))
(c-style (pel-skel-comments-strings))
(cb (nth 0 c-style)) ; comment begin: "/*" or "//"
(cc (nth 1 c-style)) ; comment continue: "**", " *" or "//"
(ce (nth 2 c-style)) ; comment end: "*/", " */", or ""
(line (make-string (length fct-name) ?=)))
;; create and return a tempo skeleton inclusion list that creates the C code
(list
'l
(pel-skel-c-separator-line) ; insert a separator line if required
cb " " line 'n
cc " " fct-name 'n
cc " " line 'n
cc 'n
cc " " purpose 'n
cc 'n
ce 'n (pel-when-text-in ce 'n)
(pel-skels-c-function-def fct-name))))
;;; ----------------------------------------------------------------------------
(provide 'custom-c-skel)
;;; custom-c-skel.el ends here