Class: Styles
Class Method Summary collapse
- .apply(pattern, *styles) ⇒ Object
-
.attribute(style, attribute) ⇒ Object
Styles.attribute “mode-line”, “background” Styles.attribute “mode-line”, “box”.
-
.clear ⇒ Object
Don’t format quotes (it can override other styles).
- .dark_bg? ⇒ Boolean
- .define(name, options) ⇒ Object
- .exand_colors(options, keys) ⇒ Object
- .font_size(size = nil) ⇒ Object
- .height ⇒ Object
- .init ⇒ Object
- .list_faces ⇒ Object
- .menu ⇒ Object
- .method_missing(*args) ⇒ Object
- .reload_styles ⇒ Object
- .size(relative = 0) ⇒ Object
- .toggle ⇒ Object
- .zoom(options = {}) ⇒ Object
Class Method Details
.apply(pattern, *styles) ⇒ Object
152 153 154 155 156 157 158 159 160 161 162 163 |
# File 'lib/xiki/styles.rb', line 152 def self.apply(pattern, *styles) # Make back-slashes double pattern.gsub!("\\", '\\\\\\\\') code = "(font-lock-add-keywords nil '(( \"#{pattern}\"\n" styles.each_with_index do |f, i| code << " (#{i} '#{f.to_s.gsub("_", "-")})\n" if f end code << " )))" $el.el4r_lisp_eval code $el.font_lock_mode 1 nil end |
.attribute(style, attribute) ⇒ Object
Styles.attribute “mode-line”, “background” Styles.attribute “mode-line”, “box”
198 199 200 |
# File 'lib/xiki/styles.rb', line 198 def self.attribute style, attribute $el.el4r_lisp_eval "(face-attribute '#{style} :#{attribute})" end |
.clear ⇒ Object
Don’t format quotes (it can override other styles)
186 187 188 |
# File 'lib/xiki/styles.rb', line 186 def self.clear $el.el4r_lisp_eval "(setq font-lock-defaults '(nil t))" end |
.dark_bg? ⇒ Boolean
97 98 99 |
# File 'lib/xiki/styles.rb', line 97 def self.dark_bg? Styles.attribute(:default, :background)[1..1][/[0-7]/] end |
.define(name, options) ⇒ Object
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 |
# File 'lib/xiki/styles.rb', line 113 def self.define name, return if ! $el self.exand_colors , [:bg, :fg] code = "(set-face-attribute (make-face '#{name.to_s.gsub("_", "-")}) nil\n" code << " :background \"##{[:bg]}\"\n" if [:bg] code << " :foreground \"##{[:fg]}\"\n" if [:fg] code << " :family \"#{[:face]}\"\n" if [:face] if [:size] size = [:size] size = self.size(size.to_i) if size.is_a? String # If a string, convert to relative size code << " :height #{size}\n" end code += [:strike] ? " :strike-through t\n" : " :strike-through nil\n" if .has_key?(:strike) code += [:underline] ? " :underline t\n" : " :underline nil\n" if .has_key?(:underline) code += [:overline] ? " :overline t\n" : " :overline nil\n" if .has_key?(:overline) code += [:bold] ? " :weight 'bold\n" : " :weight 'normal\n" if .has_key?(:bold) if [:border] border = [:border] code << if border.class == Symbol ":box nil\n" elsif border.class == String ":box '(:line-width 1 :color \"##{border}\")\n" elsif border.class == Array ":box '(:line-width #{border[1]} :color \"##{border[0]}\" :style #{border[2] || 'nil'})\n" end end code << " )" $el.el4r_lisp_eval code end |
.exand_colors(options, keys) ⇒ Object
101 102 103 104 105 106 107 |
# File 'lib/xiki/styles.rb', line 101 def self.exand_colors , keys keys.each do |key| next if ! [key] [key].sub! /^#/, '' [key].sub! /^(.)(.)(.)$/, "\\1\\1\\2\\2\\3\\3" end end |
.font_size(size = nil) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/xiki/styles.rb', line 44 def self.font_size size=nil # If nothing passed, show default sizes if ! size return " - original) #{Styles.height} - 110 - 120 - 135 - 160 - 200 - 250 " end Styles.define :default, :size=>size.to_i # To resize mode lines Notes.define_styles FileTree.define_styles nil end |
.height ⇒ Object
190 191 192 |
# File 'lib/xiki/styles.rb', line 190 def self.height $el.el4r_lisp_eval "(face-attribute 'default :height)" end |
.init ⇒ Object
165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 |
# File 'lib/xiki/styles.rb', line 165 def self.init return if ! $el # Make 'arial black' work in Linux $el.el4r_lisp_eval %` (custom-set-variables '(face-font-family-alternatives '( ("arial black" "arial" "DejaVu Sans") ("arial" "DejaVu Sans") ("verdana" "DejaVu Sans") ;("verdana" "arial") )) '(global-font-lock-mode t nil (font-lock)) ;'(font-lock-defaults '(nil t)) ; messes up Open List Faces '(show-trailing-whitespace t) '(font-lock-keywords-case-fold-search t) ) ` end |
.list_faces ⇒ Object
88 89 90 91 92 93 94 95 |
# File 'lib/xiki/styles.rb', line 88 def self.list_faces $el.with(:save_window_excursion) do $el.list_faces_display end View.to_buffer "*Faces*" nil end |
.menu ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/xiki/styles.rb', line 3 def self. ' - .font size/ - .list faces/ - api/ > Summary | How to use the Styles class. You can change the color and font of text. | You define styles, then make them apply to the text that matches | regular expression. | > Define | Styles.define :red, :bg => "d77" | > Apply | Styles.apply "apply", :red | > Define more complex font | Styles.define :blueish, | :fg => "99e", | :face => "verdana", | :size => 90, | :bold => true | > See | For styling specific text (not just a pattern): <<< @overlay/ - see/ <<< @css/list/ <<< @themes/ ' # > Apply multiple fonts and groups end |
.method_missing(*args) ⇒ Object
109 110 111 |
# File 'lib/xiki/styles.rb', line 109 def self.method_missing *args self.define *args end |
.reload_styles ⇒ Object
38 39 40 41 42 |
# File 'lib/xiki/styles.rb', line 38 def self.reload_styles Notes.define_styles FileTree.define_styles Color.define_styles end |
.size(relative = 0) ⇒ Object
202 203 204 205 206 207 |
# File 'lib/xiki/styles.rb', line 202 def self.size relative=0 # Cache so subsequent calls don't have to look up from elisp size = $el.el4r_lisp_eval "(face-attribute 'default :height)" size ||= 90 size + relative * 5 end |
.toggle ⇒ Object
80 81 82 83 84 85 86 |
# File 'lib/xiki/styles.rb', line 80 def self.toggle $el.elvar.font_lock_mode ? $el.font_lock_mode(0) : # plain text $el.font_lock_mode(true) # stylized text nil end |