]> git.eshelyaron.com Git - emacs.git/commitdiff
* lisp/svg.el: Fix typo in sample code; add minor optimization
authorStefan Monnier <monnier@iro.umontreal.ca>
Sat, 24 Apr 2021 18:07:12 +0000 (14:07 -0400)
committerStefan Monnier <monnier@iro.umontreal.ca>
Sat, 24 Apr 2021 18:07:12 +0000 (14:07 -0400)
(svg--elliptical-arc-command, svg--moveto-command)
(svg--lineto-command): Use `mapcan`.

lisp/svg.el

index 717c84788f05ee544bc6448fa2e3407356994adb..05accf4f13febf8334322fd6a7cfbffc82c335f9 100644 (file)
@@ -41,7 +41,7 @@
 ;; into the buffer:
 ;;
 ;;     (setq svg (svg-create 800 800 :stroke "orange" :stroke-width 5))
-;;     (svg-gradient svg "gradient" 'linear '(0 . "red") '(100 . "blue"))
+;;     (svg-gradient svg "gradient" 'linear '((0 . "red") (100 . "blue")))
 ;;     (save-excursion (goto-char (point-max)) (svg-insert-image svg))
 
 ;; Then add various elements to the structure:
@@ -81,7 +81,7 @@ STOPS is a list of percentage/color pairs."
   (svg--def
    svg
    (apply
-    'dom-node
+    #'dom-node
     (if (eq type 'linear)
        'linearGradient
       'radialGradient)
@@ -358,8 +358,7 @@ This is in contrast to merely setting it to 0."
                     (plist-get command-args :default-relative))))
     (intern (if relative (downcase char) (upcase char)))))
 
-(defun svg--elliptical-arc-coordinates
-    (rx ry x y &rest args)
+(defun svg--elliptical-arc-coordinates (rx ry x y &rest args)
   (list
    rx ry
    (or (plist-get args :x-axis-rotation) 0)
@@ -370,21 +369,19 @@ This is in contrast to merely setting it to 0."
 (defun svg--elliptical-arc-command (coordinates-list &rest args)
   (cons
    (svg--path-command-symbol 'a args)
-   (apply 'append
-          (mapcar
-           (lambda (coordinates)
-             (apply 'svg--elliptical-arc-coordinates
-                    coordinates))
-           coordinates-list))))
+   (mapcan
+    (lambda (coordinates)
+      (apply #'svg--elliptical-arc-coordinates
+             coordinates))
+    coordinates-list)))
 
 (defun svg--moveto-command (coordinates-list &rest args)
   (cons
    (svg--path-command-symbol 'm args)
-   (apply 'append
-          (mapcar
-           (lambda (coordinates)
-             (list (car coordinates) (cdr coordinates)))
-           coordinates-list))))
+   (mapcan
+    (lambda (coordinates)
+      (list (car coordinates) (cdr coordinates)))
+    coordinates-list)))
 
 (defun svg--closepath-command (&rest args)
   (list (svg--path-command-symbol 'z args)))
@@ -392,11 +389,10 @@ This is in contrast to merely setting it to 0."
 (defun svg--lineto-command (coordinates-list &rest args)
   (cons
    (svg--path-command-symbol 'l args)
-   (apply 'append
-          (mapcar
-           (lambda (coordinates)
-             (list (car coordinates) (cdr coordinates)))
-           coordinates-list))))
+   (mapcan
+    (lambda (coordinates)
+      (list (car coordinates) (cdr coordinates)))
+    coordinates-list)))
 
 (defun svg--horizontal-lineto-command (coordinate-list &rest args)
   (cons
@@ -411,24 +407,24 @@ This is in contrast to merely setting it to 0."
 (defun svg--curveto-command (coordinates-list &rest args)
   (cons
    (svg--path-command-symbol 'c args)
-   (apply 'append coordinates-list)))
+   (apply #'append coordinates-list)))
 
 (defun svg--smooth-curveto-command (coordinates-list &rest args)
   (cons
    (svg--path-command-symbol 's args)
-   (apply 'append coordinates-list)))
+   (apply #'append coordinates-list)))
 
 (defun svg--quadratic-bezier-curveto-command (coordinates-list
                                               &rest args)
   (cons
    (svg--path-command-symbol 'q args)
-   (apply 'append coordinates-list)))
+   (apply #'append coordinates-list)))
 
 (defun svg--smooth-quadratic-bezier-curveto-command (coordinates-list
                                                      &rest args)
   (cons
    (svg--path-command-symbol 't args)
-   (apply 'append coordinates-list)))
+   (apply #'append coordinates-list)))
 
 (defun svg--eval-path-command (command default-relative)
   (cl-letf
@@ -450,7 +446,7 @@ This is in contrast to merely setting it to 0."
         #'svg--elliptical-arc-command)
        (extended-command (append command (list :default-relative
                                                default-relative))))
-    (mapconcat 'prin1-to-string (apply extended-command) " ")))
+    (mapconcat #'prin1-to-string (apply extended-command) " ")))
 
 (defun svg-path (svg commands &rest args)
   "Add the outline of a shape to SVG according to COMMANDS.
@@ -459,7 +455,7 @@ modifiers.  If :relative is t, then coordinates are relative to
 the last position, or -- initially -- to the origin."
   (let* ((default-relative (plist-get args :relative))
          (stripped-args (svg--plist-delete args :relative))
-         (d (mapconcat 'identity
+         (d (mapconcat #'identity
                        (mapcar
                         (lambda (command)
                           (svg--eval-path-command command