Skip to content

Commit 96b9cca

Browse files
Remove dependency on names
1 parent 0df6317 commit 96b9cca

File tree

2 files changed

+40
-53
lines changed

2 files changed

+40
-53
lines changed

Cask

+1-2
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,4 @@
1010

1111
(development
1212
(depends-on "ecukes")
13-
(depends-on "espuds")
14-
(depends-on "names"))
13+
(depends-on "espuds"))

fill-function-arguments.el

+39-51
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
;; Author: David Shepherd <[email protected]>
66
;; Version: 0.3
7-
;; Package-Requires: ((names "20150618.0") (emacs "24.5"))
7+
;; Package-Requires: ((emacs "24.5"))
88
;; Keywords:
99
;; URL: https://github.com/davidshepherd7/fill-function-arguments
1010

@@ -13,28 +13,19 @@
1313

1414
;;; Code:
1515

16-
(require 'names)
1716

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
2718
t
2819
"If true dwim will fill paragraphs when in comments or strings"
2920
:group 'fill-function-arguments)
3021

31-
(defcustom first-argument-same-line
22+
(defcustom fill-function-arguments-first-argument-same-line
3223
nil
3324
"If true keep the first argument on the same line as the opening paren (e.g. as needed by xml tags)"
3425
:group 'fill-function-arguments
3526
)
3627

37-
(defcustom second-argument-same-line
28+
(defcustom fill-function-arguments-second-argument-same-line
3829
nil
3930
"If true keep the second argument on the same line as the first argument.
4031
@@ -43,13 +34,13 @@ e.g. as used in lisps like `(foo x
4334
:group 'fill-function-arguments
4435
)
4536

46-
(defcustom last-argument-same-line
37+
(defcustom fill-function-arguments-last-argument-same-line
4738
nil
4839
"If true keep the last argument on the same line as the closing paren (e.g. as done in lisp)"
4940
:group 'fill-function-arguments
5041
)
5142

52-
(defcustom argument-separator
43+
(defcustom fill-function-arguments-argument-separator
5344
","
5445
"Character separating arguments"
5546
:group 'fill-function-arguments
@@ -59,27 +50,27 @@ e.g. as used in lisps like `(foo x
5950

6051
;;; Helpers
6152

62-
(defun -in-comment-p ()
53+
(defun fill-function-arguments--in-comment-p ()
6354
"Check if we are inside a comment"
6455
(nth 4 (syntax-ppss)))
6556

66-
(defun -in-docs-p ()
57+
(defun fill-function-arguments--in-docs-p ()
6758
"Check if we are inside a string or comment"
6859
(nth 8 (syntax-ppss)))
6960

70-
(defun -opening-paren-location ()
61+
(defun fill-function-arguments--opening-paren-location ()
7162
(nth 1 (syntax-ppss)))
7263

73-
(defun -enclosing-paren ()
64+
(defun fill-function-arguments--enclosing-paren ()
7465
"Return the opening parenthesis of the enclosing parens, or nil
7566
if not inside any parens."
7667
(let ((ppss (syntax-ppss)))
7768
(when (nth 1 ppss)
7869
(char-after (nth 1 ppss)))))
7970

80-
(defun -paren-locations ()
71+
(defun fill-function-arguments--paren-locations ()
8172
"Get a pair containing the enclosing parens"
82-
(let ((start (-opening-paren-location)))
73+
(let ((start (fill-function-arguments--opening-paren-location)))
8374
(when start
8475
(cons start
8576
;; matching paren
@@ -88,83 +79,80 @@ e.g. as used in lisps like `(foo x
8879
(forward-sexp)
8980
(point))))))
9081

91-
(defun -narrow-to-funcall ()
82+
(defun fill-function-arguments--narrow-to-funcall ()
9283
(interactive)
93-
(let ((l (-paren-locations)))
84+
(let ((l (fill-function-arguments--paren-locations)))
9485
(when l
9586
(narrow-to-region (car l) (cdr l)))
9687
t))
9788

98-
(defun -single-line-p()
89+
(defun fill-function-arguments--single-line-p()
9990
"Is the current function call on a single line?"
10091
(equal (line-number-at-pos (point-max)) 1))
10192

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)
10697
(and (derived-mode-p 'sgml-mode)
107-
(not (equal (-enclosing-paren) ?<))))))
98+
(not (equal (fill-function-arguments--enclosing-paren) ?<))))))
10899

109100

110101

111102
;;; Main functions
112103

113-
(defun to-single-line ()
104+
(defun fill-function-arguments-to-single-line ()
114105
(interactive)
115106
(save-excursion
116107
(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))
119110
(goto-char (point-max))
120111
(delete-indentation)))))
121112

122-
(defun to-multi-line ()
113+
(defun fill-function-arguments-to-multi-line ()
123114
(interactive)
124-
(let ((initial-opening-paren (-opening-paren-location)))
115+
(let ((initial-opening-paren (fill-function-arguments--opening-paren-location)))
125116
(save-excursion
126117
(save-restriction
127-
(-narrow-to-funcall)
118+
(fill-function-arguments--narrow-to-funcall)
128119
(goto-char (point-min))
129120

130121
;; newline after opening paren
131122
(forward-char)
132-
(when (not first-argument-same-line)
123+
(when (not fill-function-arguments-first-argument-same-line)
133124
(insert "\n"))
134125

135-
(when second-argument-same-line
126+
(when fill-function-arguments-second-argument-same-line
136127
;; 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))
138129

139130
;; Split the arguments
140-
(while (search-forward argument-separator nil t)
131+
(while (search-forward fill-function-arguments-argument-separator nil t)
141132
;; We have to save the match data here because the functions below
142133
;; could (and sometimes do) modify it.
143134
(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)))
146137
(set-match-data saved-match-data)
147-
(replace-match (concat argument-separator "\n")))))
138+
(replace-match (concat fill-function-arguments-argument-separator "\n")))))
148139

149140
;; Newline before closing paren
150-
(when (not last-argument-same-line)
141+
(when (not fill-function-arguments-last-argument-same-line)
151142
(goto-char (point-max))
152143
(backward-char)
153144
(insert "\n"))))))
154145

155-
(defun dwim ()
146+
(defun fill-function-arguments-dwim ()
156147
(interactive)
157148
(save-restriction
158-
(-narrow-to-funcall)
149+
(fill-function-arguments--narrow-to-funcall)
159150
(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)))))
164154

165155

166-
167-
) ; end of namespace
168156

169157
(provide 'fill-function-arguments)
170158

0 commit comments

Comments
 (0)