4
4
5
5
; ; Author: David Shepherd <[email protected] >
6
6
; ; Version: 0.3
7
- ; ; Package-Requires: ((names "20150618.0") ( emacs "24.5"))
7
+ ; ; Package-Requires: ((emacs "24.5"))
8
8
; ; Keywords:
9
9
; ; URL: https://github.com/davidshepherd7/fill-function-arguments
10
10
13
13
14
14
; ;; Code:
15
15
16
- (require 'names )
17
16
18
-
19
- ; ; namespacing using names.el:
20
- ;;;### autoload
21
- (define-namespace fill-function-arguments-
22
-
23
- ; ; Tell names that it's ok to expand things inside these threading macros.
24
- :functionlike-macros (--> )
25
-
26
- (defcustom fall-through-to-fill-paragraph
17
+ (defcustom fill-function-arguments-fall-through-to-fill-paragraph
27
18
t
28
19
" If true dwim will fill paragraphs when in comments or strings"
29
20
:group 'fill-function-arguments )
30
21
31
- (defcustom first-argument-same-line
22
+ (defcustom fill-function-arguments- first-argument-same-line
32
23
nil
33
24
" If true keep the first argument on the same line as the opening paren (e.g. as needed by xml tags)"
34
25
:group 'fill-function-arguments
35
26
)
36
27
37
- (defcustom second-argument-same-line
28
+ (defcustom fill-function-arguments- second-argument-same-line
38
29
nil
39
30
" If true keep the second argument on the same line as the first argument.
40
31
@@ -43,13 +34,13 @@ e.g. as used in lisps like `(foo x
43
34
:group 'fill-function-arguments
44
35
)
45
36
46
- (defcustom last-argument-same-line
37
+ (defcustom fill-function-arguments- last-argument-same-line
47
38
nil
48
39
" If true keep the last argument on the same line as the closing paren (e.g. as done in lisp)"
49
40
:group 'fill-function-arguments
50
41
)
51
42
52
- (defcustom argument-separator
43
+ (defcustom fill-function-arguments- argument-separator
53
44
" ,"
54
45
" Character separating arguments"
55
46
:group 'fill-function-arguments
@@ -59,27 +50,27 @@ e.g. as used in lisps like `(foo x
59
50
60
51
; ;; Helpers
61
52
62
- (defun -in-comment-p ()
53
+ (defun fill-function-arguments- -in-comment-p ()
63
54
" Check if we are inside a comment"
64
55
(nth 4 (syntax-ppss )))
65
56
66
- (defun -in-docs-p ()
57
+ (defun fill-function-arguments- -in-docs-p ()
67
58
" Check if we are inside a string or comment"
68
59
(nth 8 (syntax-ppss )))
69
60
70
- (defun -opening-paren-location ()
61
+ (defun fill-function-arguments- -opening-paren-location ()
71
62
(nth 1 (syntax-ppss )))
72
63
73
- (defun -enclosing-paren ()
64
+ (defun fill-function-arguments- -enclosing-paren ()
74
65
" Return the opening parenthesis of the enclosing parens, or nil
75
66
if not inside any parens."
76
67
(let ((ppss (syntax-ppss )))
77
68
(when (nth 1 ppss)
78
69
(char-after (nth 1 ppss)))))
79
70
80
- (defun -paren-locations ()
71
+ (defun fill-function-arguments- -paren-locations ()
81
72
" Get a pair containing the enclosing parens"
82
- (let ((start (-opening-paren-location)))
73
+ (let ((start (fill-function-arguments- -opening-paren-location)))
83
74
(when start
84
75
(cons start
85
76
; ; matching paren
@@ -88,83 +79,80 @@ e.g. as used in lisps like `(foo x
88
79
(forward-sexp )
89
80
(point ))))))
90
81
91
- (defun -narrow-to-funcall ()
82
+ (defun fill-function-arguments- -narrow-to-funcall ()
92
83
(interactive )
93
- (let ((l (-paren-locations)))
84
+ (let ((l (fill-function-arguments- -paren-locations)))
94
85
(when l
95
86
(narrow-to-region (car l) (cdr l)))
96
87
t ))
97
88
98
- (defun -single-line-p()
89
+ (defun fill-function-arguments- -single-line-p ()
99
90
" Is the current function call on a single line?"
100
91
(equal (line-number-at-pos (point-max )) 1 ))
101
92
102
- (defun -suppress-argument-fill-p ()
103
- (and fall-through-to-fill-paragraph
104
- (or (-in-comment-p)
105
- (-in-docs-p)
93
+ (defun fill-function-arguments- -suppress-argument-fill-p ()
94
+ (and fill-function-arguments- fall-through-to-fill-paragraph
95
+ (or (fill-function-arguments- -in-comment-p)
96
+ (fill-function-arguments- -in-docs-p)
106
97
(and (derived-mode-p 'sgml-mode )
107
- (not (equal (-enclosing-paren) ?< ))))))
98
+ (not (equal (fill-function-arguments- -enclosing-paren) ?< ))))))
108
99
109
100
110
101
111
102
; ;; Main functions
112
103
113
- (defun to-single-line ()
104
+ (defun fill-function-arguments- to-single-line ()
114
105
(interactive )
115
106
(save-excursion
116
107
(save-restriction
117
- (-narrow-to-funcall)
118
- (while (not (-single-line-p))
108
+ (fill-function-arguments- -narrow-to-funcall)
109
+ (while (not (fill-function-arguments- -single-line-p))
119
110
(goto-char (point-max ))
120
111
(delete-indentation )))))
121
112
122
- (defun to-multi-line ()
113
+ (defun fill-function-arguments- to-multi-line ()
123
114
(interactive )
124
- (let ((initial-opening-paren (-opening-paren-location)))
115
+ (let ((initial-opening-paren (fill-function-arguments- -opening-paren-location)))
125
116
(save-excursion
126
117
(save-restriction
127
- (-narrow-to-funcall)
118
+ (fill-function-arguments- -narrow-to-funcall)
128
119
(goto-char (point-min ))
129
120
130
121
; ; newline after opening paren
131
122
(forward-char )
132
- (when (not first-argument-same-line)
123
+ (when (not fill-function-arguments- first-argument-same-line)
133
124
(insert " \n " ))
134
125
135
- (when second-argument-same-line
126
+ (when fill-function-arguments- second-argument-same-line
136
127
; ; Just move point after the second argument before we start
137
- (search-forward argument-separator nil t ))
128
+ (search-forward fill-function-arguments- argument-separator nil t ))
138
129
139
130
; ; Split the arguments
140
- (while (search-forward argument-separator nil t )
131
+ (while (search-forward fill-function-arguments- argument-separator nil t )
141
132
; ; We have to save the match data here because the functions below
142
133
; ; could (and sometimes do) modify it.
143
134
(let ((saved-match-data (match-data )))
144
- (when (save-excursion (and (not (-in-docs-p))
145
- (equal (-opening-paren-location) initial-opening-paren)))
135
+ (when (save-excursion (and (not (fill-function-arguments- -in-docs-p))
136
+ (equal (fill-function-arguments- -opening-paren-location) initial-opening-paren)))
146
137
(set-match-data saved-match-data)
147
- (replace-match (concat argument-separator " \n " )))))
138
+ (replace-match (concat fill-function-arguments- argument-separator " \n " )))))
148
139
149
140
; ; Newline before closing paren
150
- (when (not last-argument-same-line)
141
+ (when (not fill-function-arguments- last-argument-same-line)
151
142
(goto-char (point-max ))
152
143
(backward-char )
153
144
(insert " \n " ))))))
154
145
155
- (defun dwim ()
146
+ (defun fill-function-arguments- dwim ()
156
147
(interactive )
157
148
(save-restriction
158
- (-narrow-to-funcall)
149
+ (fill-function-arguments- -narrow-to-funcall)
159
150
(cond
160
- ((-suppress-argument-fill-p) (fill-paragraph ))
161
- ((-single-line-p) (to-multi-line))
162
- (t (to-single-line)))))
163
-
151
+ ((fill-function-arguments--suppress-argument-fill-p) (fill-paragraph ))
152
+ ((fill-function-arguments--single-line-p) (fill-function-arguments-to-multi-line))
153
+ (t (fill-function-arguments-to-single-line)))))
164
154
165
155
166
-
167
- ) ; end of namespace
168
156
169
157
(provide 'fill-function-arguments )
170
158
0 commit comments