+;;; The `custom-comment' Widget.
+
+;; like the editable field
+(defface custom-comment-face '((((class grayscale color)
+ (background light))
+ (:background "gray85"))
+ (((class grayscale color)
+ (background dark))
+ (:background "dim gray"))
+ (t
+ (:italic t)))
+ "Face used for comments on variables or faces"
+ :group 'custom-faces)
+
+;; like font-lock-comment-face
+(defface custom-comment-tag-face
+ '((((class color) (background dark)) (:foreground "gray80"))
+ (((class color) (background light)) (:foreground "blue4"))
+ (((class grayscale) (background light))
+ (:foreground "DimGray" :bold t :italic t))
+ (((class grayscale) (background dark))
+ (:foreground "LightGray" :bold t :italic t))
+ (t (:bold t)))
+ "Face used for variables or faces comment tags"
+ :group 'custom-faces)
+
+(define-widget 'custom-comment 'string
+ "User comment"
+ :tag "Comment"
+ :help-echo "Edit a comment here"
+ :sample-face 'custom-comment-tag-face
+ :value-face 'custom-comment-face
+ :value-set 'custom-comment-value-set
+ :create 'custom-comment-create
+ :delete 'custom-comment-delete)
+
+(defun custom-comment-create (widget)
+ (let (ext)
+ (widget-default-create widget)
+ (widget-put widget :comment-extent
+ (setq ext (make-extent (widget-get widget :from)
+ (widget-get widget :to))))
+ (set-extent-property ext 'start-open t)
+ (when (equal (widget-get widget :value) "")
+ (set-extent-property ext 'invisible t))
+ ))
+
+(defun custom-comment-delete (widget)
+ (widget-default-delete widget)
+ (delete-extent (widget-get widget :comment-extent)))
+
+(defun custom-comment-value-set (widget value)
+ (widget-default-value-set widget value)
+ (if (equal value "")
+ (set-extent-property (widget-get widget :comment-extent)
+ 'invisible t)
+ (set-extent-property (widget-get widget :comment-extent)
+ 'invisible nil)))
+
+;; Those functions are for the menu. WIDGET is NOT the comment widget. It's
+;; the global custom one
+(defun custom-comment-show (widget)
+ (set-extent-property
+ (widget-get (widget-get widget :comment-widget) :comment-extent)
+ 'invisible nil))
+
+(defun custom-comment-invisible-p (widget)
+ (extent-property
+ (widget-get (widget-get widget :comment-widget) :comment-extent)
+ 'invisible))
+