branch: externals/colorful-mode
commit ea81e85fc7185839e0bba1abdeee4bf3a7623d74
Author: Elijah Gabe P. <[email protected]>
Commit: Elijah Gabe P. <[email protected]>
Small fixes.
* colorful-mode.el (colorful-convert-and-change-color):
Use interactive spec.
(colorful--get-css-variable-color): Use `and' instead `ignore-errors'.
(colorful--colorize): Formatting.
---
colorful-mode.el | 34 +++++++++++++++++++---------------
1 file changed, 19 insertions(+), 15 deletions(-)
diff --git a/colorful-mode.el b/colorful-mode.el
index 9fdce09728..ee5fac4c50 100644
--- a/colorful-mode.el
+++ b/colorful-mode.el
@@ -467,10 +467,14 @@ BEG is the position to check for the overlay."
;;;; User Interactive Functions
(defun colorful-convert-and-change-color (&optional beg end)
- "Convert color to other format and replace color at point or active mark.
-If mark is active, convert colors in mark."
- (interactive "*r")
- (if mark-active
+ "Convert color to other format and replace color at point or active region.
+If region is active, convert colors in mark."
+ (interactive
+ (progn (barf-if-buffer-read-only)
+ (if (use-region-p)
+ (list (region-beginning) (region-end)))))
+
+ (if (and beg end)
(let* ((choices '(("Hexadecimal color format" . hex)
("Emacs color name" . name)))
;; Start prompt.
@@ -679,10 +683,10 @@ REGEXP must have a group that contains the color value."
(when (re-search-backward ,regexp nil t)
;; Get color value from colorful overlay.
;; if not color value found, use the one from REGEXP 1st group.
- (setq color (or (ignore-errors
- (overlay-get (colorful--find-overlay
- (match-beginning 1))
- 'colorful--overlay-color))
+ (setq color (or (and (colorful--find-overlay (match-beginning 1)) ;
Ensure overlay exists.
+ (overlay-get (colorful--find-overlay
+ (match-beginning 1))
+ 'colorful--overlay-color))
(match-string-no-properties 1))))))
(defun colorful--colorize (kind &optional match)
@@ -755,15 +759,15 @@ REGEXP must have a group that contains the color value."
;; Find whole buffer for last @define-color match-1 found
;; and get its color value.
(colorful--get-css-variable-color
- (rx (seq "@define_color"
- (one-or-more space)
- (literal match-2)
- (one-or-more space)
- (group (opt "#") (one-or-more (any "0-9A-Za-z")))))))
+ (rx (seq "@define_color"
+ (one-or-more space)
+ (literal match-2)
+ (one-or-more space)
+ (group (opt "#") (one-or-more (any "0-9A-Za-z")))))))
((string= match-1 "var")
(colorful--get-css-variable-color
- (rx (seq (literal match-2) ":" (zero-or-more space)
- (group (opt "#") (one-or-more (any "0-9A-Za-z"))))))))))
+ (rx (seq (literal match-2) ":" (zero-or-more space)
+ (group (opt "#") (one-or-more (any "0-9A-Za-z"))))))))))
;; Ensure that string is a valid color and that string is non-nil
(if (and color (color-defined-p color))