Skip to content

Commit e4ca05d

Browse files
committed
Rename convert-shorthand-fn -> promote-fn-literal
1 parent eebb353 commit e4ca05d

File tree

2 files changed

+18
-18
lines changed

2 files changed

+18
-18
lines changed

clojure-mode.el

+8-8
Original file line numberDiff line numberDiff line change
@@ -2767,8 +2767,8 @@ With a numeric prefix argument the let is introduced N lists up."
27672767
(interactive)
27682768
(clojure--move-to-let-internal (read-from-minibuffer "Name of bound symbol: ")))
27692769

2770-
;;; Shorthand fn conversion
2771-
(defun clojure--gather-shorthand-args ()
2770+
;;; Promoting #() function literals
2771+
(defun clojure--gather-fn-literal-args ()
27722772
"Return a cons cell (ARITY . VARARG)
27732773
ARITY is number of arguments in the function,
27742774
VARARG is a boolean of whether it takes a variable argument %&."
@@ -2788,7 +2788,7 @@ VARARG is a boolean of whether it takes a variable argument %&."
27882788
(string-to-number s))))))))
27892789
(cons arity vararg))))
27902790

2791-
(defun clojure--substitute-shorthand-arg (arg sub end)
2791+
(defun clojure--substitute-fn-literal-arg (arg sub end)
27922792
"ARG is either a number or the symbol '&.
27932793
SUB is a string to substitute with, and
27942794
END marks the end of the fn expression"
@@ -2799,7 +2799,7 @@ END marks the end of the fn expression"
27992799
(not (clojure--in-string-p)))
28002800
(replace-match sub))))))
28012801

2802-
(defun clojure-convert-shorthand-fn ()
2802+
(defun clojure-promote-fn-literal ()
28032803
"Convert a #(...) function into (fn [...] ...), prompting for the argument names."
28042804
(interactive)
28052805
(when-let (beg (clojure-string-start))
@@ -2808,7 +2808,7 @@ END marks the end of the fn expression"
28082808
(ignore-errors (forward-char 1))
28092809
(re-search-backward "#(" (save-excursion (beginning-of-defun) (point)) 'noerror))
28102810
(let* ((end (save-excursion (clojure-forward-logical-sexp) (point-marker)))
2811-
(argspec (clojure--gather-shorthand-args))
2811+
(argspec (clojure--gather-fn-literal-args))
28122812
(arity (car argspec))
28132813
(vararg (cdr argspec)))
28142814
(delete-char 1)
@@ -2820,14 +2820,14 @@ END marks the end of the fn expression"
28202820
(let ((name (read-string (format "Name of argument %d: " n))))
28212821
(when (/= n 1) (insert " "))
28222822
(insert name)
2823-
(clojure--substitute-shorthand-arg n name end)))
2823+
(clojure--substitute-fn-literal-arg n name end)))
28242824
(number-sequence 1 arity))
28252825
(when vararg
28262826
(insert " & ")
28272827
(let ((name (read-string "Name of variadic argument: ")))
28282828
(insert name)
2829-
(clojure--substitute-shorthand-arg '& name end)))))
2830-
(user-error "No #() shorthand at point!")))
2829+
(clojure--substitute-fn-literal-arg '& name end)))))
2830+
(user-error "No #() literal at point!")))
28312831

28322832
;;; Renaming ns aliases
28332833

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

+10-10
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)