branch: elpa/inf-ruby
commit 3cdf30dc737a828f956564cfbe38b22acba46bab
Author: tunnes <[email protected]>
Commit: tunnes <[email protected]>

    Apply code review - remove cl-lib and optional args
---
 inf-ruby.el | 153 ++++++++++++++++++++++++++++--------------------------------
 1 file changed, 71 insertions(+), 82 deletions(-)

diff --git a/inf-ruby.el b/inf-ruby.el
index 2769cdb988..b0930f24ec 100755
--- a/inf-ruby.el
+++ b/inf-ruby.el
@@ -62,7 +62,6 @@
 
 ;;; Code:
 
-(require 'cl-lib)
 (require 'comint)
 (require 'compile)
 (require 'ruby-mode)
@@ -534,10 +533,7 @@ Never throws errors, and can be used in an overlay's
 modification-hooks."
   (ignore-errors (delete-overlay ov)))
 
-(cl-defun inf-ruby--make-result-overlay (value &rest props &key where duration 
(type 'result)
-                                           (format (concat " => %s "))
-                                           (prepend-face 
'inf-ruby-result-overlay-face)
-                                           &allow-other-keys)
+(defun inf-ruby--make-result-overlay (value where duration &rest props)
   "Place an overlay displaying VALUE at the end of line.
 VALUE is used as the overlay's after-string property, meaning it
 is displayed at the end of the overlay.  The overlay itself is
@@ -546,82 +542,77 @@ Return nil if the overlay was not placed or if it might 
not be
 visible, and return the overlay otherwise.
 Return the overlay if it was placed successfully, and nil if it
 failed.
-This function takes some optional keyword arguments:
-- If WHERE is a number or a marker, apply the overlay over the
-  entire line at that place (defaulting to `point').  If it is a
-  cons cell, the car and cdr determine the start and end of the
-  overlay.
-- TYPE is passed to `inf-ruby--make-overlay' (defaults to `result').
-- FORMAT is a string passed to `format'.  It should have exactly
-  one %s construct (for VALUE).
 All arguments beyond these (PROPS) are properties to be used on
 the overlay."
-  (declare (indent 1))
-  (while (keywordp (car props))
-    (setq props (cddr props)))
-  ;; If the marker points to a dead buffer, don't do anything.
-  (let ((buffer (cond
-                 ((markerp where) (marker-buffer where))
-                 ((markerp (car-safe where)) (marker-buffer (car where)))
-                 (t (current-buffer)))))
-    (with-current-buffer buffer
-      (save-excursion
-        (when (number-or-marker-p where)
-          (goto-char where))
-        ;; Make sure the overlay is actually at the end of the sexp.
-        (skip-chars-backward "\r\n[:blank:]")
-        (let* ((beg (if (consp where)
-                        (car where)
-                      (save-excursion
-                        (backward-sexp 1)
-                        (point))))
-               (end (if (consp where)
-                        (cdr where)
-                      (line-end-position)))
-               (display-string (format format value))
-               (o nil))
-          (remove-overlays beg end 'category type)
-          (funcall #'put-text-property
-                   0 (length display-string)
-                   'face prepend-face
-                   display-string)
-          ;; If the display spans multiple lines or is very long, display it at
-          ;; the beginning of the next line.
-          (when (or (string-match "\n." display-string)
-                    (> (string-width display-string)
-                       (- (window-width) (current-column))))
-            (setq display-string (concat " \n" display-string)))
-          ;; Put the cursor property only once we're done manipulating the
-          ;; string, since we want it to be at the first char.
-          (put-text-property 0 1 'cursor 0 display-string)
-          (when (> (string-width display-string) (* 3 (window-width)))
-            (setq display-string
-                  (concat (substring display-string 0 (* 3 (window-width)))
-                          "...\nResult truncated.")))
-          ;; Create the result overlay.
-          (setq o (apply #'inf-ruby--make-overlay
-                         beg end type
-                         'after-string display-string
-                         props))
-          (pcase duration
-            ((pred numberp) (run-at-time duration nil 
#'inf-ruby--delete-overlay o))
-            (`command (if this-command
-                          (add-hook 'pre-command-hook
-                                    #'inf-ruby--remove-result-overlay
-                                    nil 'local)
-                        (inf-ruby--remove-result-overlay))))
-          (let ((win (get-buffer-window buffer)))
-            ;; Left edge is visible.
-            (when (and win
-                       (<= (window-start win) (point))
-                       ;; In 24.3 `<=' is still a binary predicate.
-                       (<= (point) (window-end win))
-                       ;; Right edge is visible. This is a little conservative
-                       ;; if the overlay contains line breaks.
-                       (or (< (+ (current-column) (string-width value))
-                              (window-width win))
-                           (not truncate-lines)))
-              o)))))))
+  (let ((format " => %s ")
+       (prepend-face 'inf-ruby-result-overlay-face)
+       (type 'result))
+    (declare (indent 1))
+    (while (keywordp (car props))
+      (setq props (cddr props)))
+    ;; If the marker points to a dead buffer, don't do anything.
+    (let ((buffer (cond
+                   ((markerp where) (marker-buffer where))
+                   ((markerp (car-safe where)) (marker-buffer (car where)))
+                   (t (current-buffer)))))
+      (with-current-buffer buffer
+       (save-excursion
+          (when (number-or-marker-p where)
+            (goto-char where))
+          ;; Make sure the overlay is actually at the end of the sexp.
+          (skip-chars-backward "\r\n[:blank:]")
+          (let* ((beg (if (consp where)
+                          (car where)
+                       (save-excursion
+                          (backward-sexp 1)
+                          (point))))
+                (end (if (consp where)
+                          (cdr where)
+                       (line-end-position)))
+                (display-string (format format value))
+                (o nil))
+            (remove-overlays beg end 'category type)
+            (funcall #'put-text-property
+                     0 (length display-string)
+                     'face prepend-face
+                     display-string)
+            ;; If the display spans multiple lines or is very long, display it 
at
+            ;; the beginning of the next line.
+            (when (or (string-match "\n." display-string)
+                      (> (string-width display-string)
+                        (- (window-width) (current-column))))
+              (setq display-string (concat " \n" display-string)))
+            ;; Put the cursor property only once we're done manipulating the
+            ;; string, since we want it to be at the first char.
+            (put-text-property 0 1 'cursor 0 display-string)
+            (when (> (string-width display-string) (* 3 (window-width)))
+              (setq display-string
+                    (concat (substring display-string 0 (* 3 (window-width)))
+                            "...\nResult truncated.")))
+            ;; Create the result overlay.
+            (setq o (apply #'inf-ruby--make-overlay
+                           beg end type
+                           'after-string display-string
+                           props))
+            (pcase duration
+              ((pred numberp) (run-at-time duration nil 
#'inf-ruby--delete-overlay o))
+              (`command (if this-command
+                            (add-hook 'pre-command-hook
+                                      #'inf-ruby--remove-result-overlay
+                                      nil 'local)
+                          (inf-ruby--remove-result-overlay))))
+            (let ((win (get-buffer-window buffer)))
+              ;; Left edge is visible.
+              (when (and win
+                        (<= (window-start win) (point))
+                        ;; In 24.3 `<=' is still a binary predicate.
+                        (<= (point) (window-end win))
+                        ;; Right edge is visible. This is a little conservative
+                        ;; if the overlay contains line breaks.
+                        (or (< (+ (current-column) (string-width value))
+                               (window-width win))
+                             (not truncate-lines)))
+               o))))))))
 
 (defun inf-ruby--remove-result-overlay ()
   "Remove result overlay from current buffer.
@@ -631,9 +622,7 @@ This function also removes itself from `pre-command-hook'."
 
 (defun inf-ruby--eval-overlay (value)
   "Make overlay for VALUE at POINT."
-  (inf-ruby--make-result-overlay (format "%S" value)
-                            :where (point)
-                            :duration 'command)
+  (inf-ruby--make-result-overlay (format "%S" value) (point) 'command)
   value)
 
 

Reply via email to