summaryrefslogtreecommitdiff
path: root/cider-util.el
diff options
context:
space:
mode:
authorJeff Valk <jv@jeffvalk.com>2014-06-07 22:40:37 -0400
committerJeff Valk <jv@jeffvalk.com>2014-06-07 23:34:23 -0400
commit016c6cf1ea66552602a96afb9cba53c429a018d3 (patch)
treec040b1a97254b62bcfa42ee06ced59cf33a6007b /cider-util.el
parent27ecce4541886ca3f98591cbf222166d9f15bc74 (diff)
Move generally useful functions to cider-util.
Diffstat (limited to 'cider-util.el')
-rw-r--r--cider-util.el38
1 files changed, 38 insertions, 0 deletions
diff --git a/cider-util.el b/cider-util.el
index 04b1fbba..8f6d1cf5 100644
--- a/cider-util.el
+++ b/cider-util.el
@@ -31,6 +31,7 @@
;;; Code:
(require 'dash)
+(require 'cl-lib)
;;; Compatibility
(eval-and-compile
@@ -63,6 +64,27 @@ buffer-local wherever it is set."
(lambda (buffer) (with-current-buffer buffer (derived-mode-p 'clojure-mode)))
(buffer-list)))
+;;; Text properties
+
+(defmacro cider-propertize-region (props &rest body)
+ "Execute BODY and add PROPS to all the text it inserts.
+More precisely, PROPS are added to the region between the point's
+positions before and after executing BODY."
+ (let ((start (cl-gensym)))
+ `(let ((,start (point)))
+ (prog1 (progn ,@body)
+ (add-text-properties ,start (point) ,props)))))
+
+(put 'cider-propertize-region 'lisp-indent-function 1)
+
+(defun cider-property-bounds (prop)
+ "Return the the positions of the previous and next change to PROP.
+PROP is the name of a text property."
+ (assert (get-text-property (point) prop))
+ (let ((end (next-single-char-property-change (point) prop)))
+ (list (previous-single-char-property-change end prop) end)))
+;;; Font lock
+
(defun cider-font-lock-as (mode string)
"Use MODE to font-lock the STRING."
(with-temp-buffer
@@ -124,6 +146,22 @@ respectively."
nil
nil))
+;;; Colors
+
+(defun cider-scale-color (color scale)
+ "For a COLOR hex string or name, adjust intensity of RGB components by SCALE."
+ (let* ((rgb (color-values color))
+ (scaled-rgb (mapcar (lambda (n)
+ (format "%04x" (round (+ n (* scale 65535)))))
+ rgb)))
+ (apply 'concat "#" scaled-rgb)))
+
+(defun cider-scale-background-color ()
+ "Scale the current background color to get a slighted muted version."
+ (let ((color (frame-parameter nil 'background-color))
+ (dark (eq (frame-parameter nil 'background-mode) 'dark)))
+ (cider-scale-color color (if dark 0.05 -0.05))))
+
(defun cider-format-pprint-eval (form)
"Return a string of Clojure code that will eval and pretty-print FORM."
(format "(let [x %s] (clojure.pprint/pprint x) x)" form))