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
|
# STYLE_GUIDE for MMOSMacs
Much of this Style Guide was taken from
[bbatsov/emacs-lisp-style-guide](https://github.com/bbatsov/emacs-lisp-style-guide).
# General guidelines
- Use spaces for indentation. Do not use tabs anywhere.
- Where feasible, avoid making lines longer than 72 chars.
- Avoid trailing whitespace.
## Organization
Emacs Lisp files should begin with a header. The first line of the
header should include the filename, a very brief comment (2-5 words),
and the `-*- lexical-binding: t; -*-` thing. The next line(s) should be
a more detailed description of the file and it's purpose.
```elisp
;;; -*- lexical-binding: t; -*-
;;; init.el
;;
;; Main config file for MMOSMacs; the glue that binds the modules
;; together. Provides package management, performance tweaks, and
;; integrates all the other MMOSMacs modules.
```
All Emacs Lisp files are organized into Sections and Subsections using
comment decorations. Section titles begin with `;;;`, are ALL CAPS, and
their decorations extend up to 72 chars. Subsections begin with `;;`
and their decorations extend up to 36 chars. Titles should be underlined
with dashes on the proceeding line. Explanatory comments go below the
title underline, and an additional 36-or-72-char line goes at the bottom
of the header.
Each subsection should have 2 blank lines between the top line of the
header and the bottom line of code from the previous subsection. Only
one line goes between the Section header and the first Subsection, as
well as between portions of code within the same subsection. 4 lines go
between a new Section header and the previous bit of code.
```elisp
;; integrates all the other MMOSMacs modules.
;; ---------------------------------------------------------------------
;;; FIRST SECTION TITLE
;; --------------------
;; Comments about the purpose of the section go here.
;; It should be concise. Don't go into too much detail.
;; ---------------------------------------------------------------------
;; ---------------------------------
;; Subsection Title
;; ----------------
;; Subsection explanatory text goes
;; here. Limit the line length to 36
;; chars to maintain the visual
;; "togetherness" of the header.
;;
;; Notice only 1 space between the
;; Section header and the top of the
;; first Subsection header.
;; ---------------------------------
;; `something` is a package I bet
(use-package something
:straight t
:init
(setq some-crap nil))
;; `something-else` is a little less
;; likely to be a package
(use-package something-else
:straight t)
;; ---------------------------------
;; Subsection Title
;; ----------------
;; Notice the 2 lines separating
;; each Subsection.
;; ---------------------------------
;; I really don't know what to write
;; in these example comments.
(use-package some-other-thing
:straight
:init
(other-thing-mode))
;; ---------------------------------------------------------------------
;;; SECOND SECTION TITLE
;; ---------------------
;; Notice the 4 empty lines above this section.
;; This provides visual separation; easier on the eyes.
;; ---------------------------------------------------------------------
```
## Comments & Annotations
- Write heading comments with 3 semicolons, and regular comments with 2.
- Write margin comments with 1 semicolon.
- Leave 1 space between the semicolons and the comment text.
- Comments longer than 1 word are capitalized and use punctuation.
```elisp
;;; This is a heading comment
;; This is a regular comment with more words and stuff.
;; Something something something.
(defun foo (bar)
(something something
something-else)) ; for some other reason
```
## Docstrings
- Begin docstrings with a terse, complete sentence. Use imperative
language (e.g. "Verify" instead of "Verifies")
- When a function takes arguments, mention what the arguments do,
whether they are optional or required, etc. Describe the arguments in
UPPERCASE, and describe them in the order they are used in the function.
- Do not indent subsequent lines of a docstring. It looks nice in source
code but looks bizarre when viewed in Emacs.
```elisp
;; good
(defun goto-line (line &optional buffer)
"Go to LINE, counting from line 1 at beginning of buffer.
If called interactively, a numeric prefix argument specifies
LINE; without a numeric prefix argument, read LINE from the
minibuffer..."
...)
;; bad
(defun goto-line (line &optional buffer)
"Go to LINE, counting from line 1 at beginning of buffer.
If called interactively, a numeric prefix argument specifies
LINE; without a numeric prefix argument, read LINE from the
minibuffer..."
...)
```
|