aboutsummaryrefslogtreecommitdiffstats
path: root/emacs
diff options
context:
space:
mode:
authorGravatar Tom Willemse2017-01-11 23:56:12 +0100
committerGravatar Tom Willemse2017-01-11 23:56:12 +0100
commitf76981a7b12b293828b0f71a62d92cb1d5f8317c (patch)
treeb70d6aea5fd49ca12c513be2033747d51785efdb /emacs
parent89379c5f99ee1166d55548f732499b0cf907642c (diff)
downloadnew-dotfiles-f76981a7b12b293828b0f71a62d92cb1d5f8317c.tar.gz
new-dotfiles-f76981a7b12b293828b0f71a62d92cb1d5f8317c.zip
Add command to toggle !important CSS flag
Diffstat (limited to 'emacs')
-rw-r--r--emacs/.emacs.d/init/oni-css-mode-init.org41
1 files changed, 41 insertions, 0 deletions
diff --git a/emacs/.emacs.d/init/oni-css-mode-init.org b/emacs/.emacs.d/init/oni-css-mode-init.org
index e5531e3..447f9ec 100644
--- a/emacs/.emacs.d/init/oni-css-mode-init.org
+++ b/emacs/.emacs.d/init/oni-css-mode-init.org
@@ -45,3 +45,44 @@ regexps.
(add-to-list 'compilation-error-regexp-alist
(list oni:scss-error-regexp 2 1 nil 2 2)))
#+END_SRC
+
+Add a command to toggle the =!important= flag on CSS properties.
+
+#+BEGIN_SRC emacs-lisp
+ (defun oni:css-property-important-p ()
+ "Return whether or not the current property is important."
+ (save-excursion
+ (beginning-of-line)
+ (re-search-forward "!important" (line-end-position) :noerror)))
+
+ (defun oni:css-add-important ()
+ "Add an important flag to the property on the current line."
+ (interactive)
+ (unless (oni:css-property-important-p)
+ (save-excursion
+ (end-of-line)
+ (when (re-search-backward ";" (line-beginning-position) :noerror)
+ (insert " !important")))))
+
+ (defun oni:css-remove-important ()
+ "Remove the important flag from the property on the current line."
+ (interactive)
+ (when (oni:css-property-important-p)
+ (save-excursion
+ (end-of-line)
+ (when (re-search-backward " !important" (line-beginning-position) :noerror)
+ (replace-match "")))))
+
+ (defun oni:css-toggle-important ()
+ "Toggle the important flag on the property on the current line."
+ (interactive)
+ (if (oni:css-property-important-p)
+ (oni:css-remove-important)
+ (oni:css-add-important)))
+#+END_SRC
+
+Add a keybinding to toggle the =!important= flag on the current line.
+
+#+BEGIN_SRC emacs-lisp
+ (global-set-key (kbd "C-c !") #'oni:css-toggle-important)
+#+END_SRC