Skip to content

Commit bec0de2

Browse files
committed
Rename convert-shorthand-fn -> promote-fn-literal
1 parent 430baf6 commit bec0de2

File tree

2 files changed

+18
-18
lines changed

2 files changed

+18
-18
lines changed

clojure-mode.el

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2769,8 +2769,8 @@ With a numeric prefix argument the let is introduced N lists up."
27692769
(interactive)
27702770
(clojure--move-to-let-internal (read-from-minibuffer "Name of bound symbol: ")))
27712771

2772-
;;; Shorthand fn conversion
2773-
(defun clojure--gather-shorthand-args ()
2772+
;;; Promoting #() function literals
2773+
(defun clojure--gather-fn-literal-args ()
27742774
"Return a cons cell (ARITY . VARARG)
27752775
ARITY is number of arguments in the function,
27762776
VARARG is a boolean of whether it takes a variable argument %&."
@@ -2790,7 +2790,7 @@ VARARG is a boolean of whether it takes a variable argument %&."
27902790
(string-to-number s))))))))
27912791
(cons arity vararg))))
27922792

2793-
(defun clojure--substitute-shorthand-arg (arg sub end)
2793+
(defun clojure--substitute-fn-literal-arg (arg sub end)
27942794
"ARG is either a number or the symbol '&.
27952795
SUB is a string to substitute with, and
27962796
END marks the end of the fn expression"
@@ -2801,7 +2801,7 @@ END marks the end of the fn expression"
28012801
(not (clojure--in-string-p)))
28022802
(replace-match sub))))))
28032803

2804-
(defun clojure-convert-shorthand-fn ()
2804+
(defun clojure-promote-fn-literal ()
28052805
"Convert a #(...) function into (fn [...] ...), prompting for the argument names."
28062806
(interactive)
28072807
(when-let (beg (clojure-string-start))
@@ -2810,7 +2810,7 @@ END marks the end of the fn expression"
28102810
(ignore-errors (forward-char 1))
28112811
(re-search-backward "#(" (save-excursion (beginning-of-defun) (point)) 'noerror))
28122812
(let* ((end (save-excursion (clojure-forward-logical-sexp) (point-marker)))
2813-
(argspec (clojure--gather-shorthand-args))
2813+
(argspec (clojure--gather-fn-literal-args))
28142814
(arity (car argspec))
28152815
(vararg (cdr argspec)))
28162816
(delete-char 1)
@@ -2822,14 +2822,14 @@ END marks the end of the fn expression"
28222822
(let ((name (read-string (format "Name of argument %d: " n))))
28232823
(when (/= n 1) (insert " "))
28242824
(insert name)
2825-
(clojure--substitute-shorthand-arg n name end)))
2825+
(clojure--substitute-fn-literal-arg n name end)))
28262826
(number-sequence 1 arity))
28272827
(when vararg
28282828
(insert " & ")
28292829
(let ((name (read-string "Name of variadic argument: ")))
28302830
(insert name)
2831-
(clojure--substitute-shorthand-arg '& name end)))))
2832-
(user-error "No #() shorthand at point!")))
2831+
(clojure--substitute-fn-literal-arg '& name end)))))
2832+
(user-error "No #() literal at point!")))
28332833

28342834
;;; Renaming ns aliases
28352835

test/clojure-mode-convert-fn-test.el renamed to test/clojure-mode-promote-fn-literal-test.el

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
;;; clojure-mode-convert-fn-test.el --- Clojure Mode: convert fn syntax -*- lexical-binding: t; -*-
1+
;;; clojure-mode-promote-fn-literal-test.el --- Clojure Mode: convert fn syntax -*- lexical-binding: t; -*-
22

33
;; This file is not part of GNU Emacs.
44

@@ -17,14 +17,14 @@
1717

1818
;;; Commentary:
1919

20-
;; Tests for clojure-convert-shorthand-fn
20+
;; Tests for clojure-promote-fn-literal
2121

2222
;;; Code:
2323

2424
(require 'clojure-mode)
2525
(require 'buttercup)
2626

27-
(describe "clojure-convert-shorthand-fn"
27+
(describe "clojure-promote-fn-literal"
2828
:var (names)
2929

3030
(before-each
@@ -34,19 +34,19 @@
3434
(when-refactoring-it "should convert 0-arg fns"
3535
"#(rand)"
3636
"(fn [] (rand))"
37-
(clojure-convert-shorthand-fn))
37+
(clojure-promote-fn-literal))
3838

3939
(when-refactoring-it "should convert 1-arg fns"
4040
"#(= % 1)"
4141
"(fn [x] (= x 1))"
4242
(setq names '("x"))
43-
(clojure-convert-shorthand-fn))
43+
(clojure-promote-fn-literal))
4444

4545
(when-refactoring-it "should convert 2-arg fns"
46-
"#(conj (pop %1) (assoc (peek %1) %2 (* %2 %2)))"
46+
"#(conj (pop %) (assoc (peek %1) %2 (* %2 %2)))"
4747
"(fn [acc x] (conj (pop acc) (assoc (peek acc) x (* x x))))"
4848
(setq names '("acc" "x"))
49-
(clojure-convert-shorthand-fn))
49+
(clojure-promote-fn-literal))
5050

5151
(when-refactoring-it "should convert variadic fns"
5252
;; from https://hypirion.com/musings/swearjure
@@ -55,18 +55,18 @@
5555
"(fn [v & vs] (* (`[~@vs] (+))
5656
((v (+)) v (- (`[~@vs] (+)) (*)))))"
5757
(setq names '("v" "vs"))
58-
(clojure-convert-shorthand-fn))
58+
(clojure-promote-fn-literal))
5959

6060
(when-refactoring-it "should ignore strings and comments"
6161
"#(format \"%2\" ;; FIXME: %2 is an illegal specifier
6262
%7) "
6363
"(fn [_ _ _ _ _ _ id] (format \"%2\" ;; FIXME: %2 is an illegal specifier
6464
id)) "
6565
(setq names '("_" "_" "_" "_" "_" "_" "id"))
66-
(clojure-convert-shorthand-fn)))
66+
(clojure-promote-fn-literal)))
6767

6868

6969
(provide 'clojure-mode-convert-fn-test)
7070

7171

72-
;;; clojure-mode-convert-fn-test.el ends here
72+
;;; clojure-mode-promote-fn-literal-test.el ends here

0 commit comments

Comments
 (0)