Class: LangHelp::LangHelp
- Includes:
- DisplayResult
- Defined in:
- lib/el4r/emacsruby/langhelp.rb
Overview
/LangHelpInternal
Constant Summary collapse
- INDEX_BUFFER =
"*langhelp index*"
Instance Attribute Summary collapse
-
#conf ⇒ Object
readonly
Returns the value of attribute conf.
Instance Method Summary collapse
- #abbreviate_url ⇒ Object
- #define_faces ⇒ Object
- #defun_langhelp_menu_mode ⇒ Object
- #defun_langhelp_occur ⇒ Object
- #defun_langhelp_setup_index_buffer ⇒ Object
- #defun_langhelp_update(x) ⇒ Object
-
#initialize(x = {}) ⇒ LangHelp
constructor
A new instance of LangHelp.
- #key_binding_default ⇒ Object
- #narrowing? ⇒ Boolean
- #real_mmode ⇒ Object
- #set_tab_width ⇒ Object
- #set_which_func ⇒ Object
- #setup_font_lock ⇒ Object
- #setup_man ⇒ Object
- #setup_w3m ⇒ Object
Methods included from DisplayResult
#display_result, #display_result_buffer, #flash_line, #search_anchor, #search_line
Constructor Details
#initialize(x = {}) ⇒ LangHelp
Returns a new instance of LangHelp.
268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 |
# File 'lib/el4r/emacsruby/langhelp.rb', line 268 def initialize(x={}) el_require :info el_require :cl funcall :put, :ee_anchor_format, :safe_local_variable, :stringp define_faces defun_langhelp_update x langhelp_update defun_langhelp_setup_index_buffer setup_man setup_w3m defun_langhelp_occur langhelp_setup_index_buffer defalias :lh, :progn end |
Instance Attribute Details
#conf ⇒ Object (readonly)
Returns the value of attribute conf.
266 267 268 |
# File 'lib/el4r/emacsruby/langhelp.rb', line 266 def conf @conf end |
Instance Method Details
#abbreviate_url ⇒ Object
693 694 695 |
# File 'lib/el4r/emacsruby/langhelp.rb', line 693 def abbreviate_url abbreviate_file_name((elvar.w3m_current_url || '').sub(%r!^file://!,'')) end |
#define_faces ⇒ Object
286 287 288 289 290 291 292 293 294 295 296 297 |
# File 'lib/el4r/emacsruby/langhelp.rb', line 286 def define_faces el4r_lisp_eval <<-EOL (progn (defface langhelp-sexp-face '((t (:foreground "SteelBlue" :underline t))) nil) (defface langhelp-title-face '((t (:background "white" :foreground "black"))) nil) (setq langhelp-sexp-face 'langhelp-sexp-face) (setq langhelp-title-face 'langhelp-title-face) ) EOL end |
#defun_langhelp_menu_mode ⇒ Object
375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 |
# File 'lib/el4r/emacsruby/langhelp.rb', line 375 def set_which_func defvar(:ee_anchor_format, "<<%s>>") defvar(:langhelp_revert_buffer_function, nil) define_derived_mode(:langhelp_menu_mode, :fundamental_mode, "LH", "Major mode for selecting a langhelp link.") do setup_font_lock make_local_variable :langhelp_revert_buffer_function elvar.truncate_lines = true make_local_variable :outline_regexp elvar.outline_regexp = '####\|# Node:' make_local_variable :kill_whole_line elvar.kill_whole_line = true elvar. = :lh_imenu_create_index elvar.header_line_format = el4r_lisp_eval %('(which-func-mode ("" which-func-format))) # ' set_tab_width which_func_mode 1 if fboundp :which_func_mode hl_line_mode 1 if fboundp :hl_line_mode end suppress_keymap elvar. key_binding = key_binding_default.update(conf[:KEY_BINDING] || {}) key_binding.each do |key, cmd| define_key(:langhelp_menu_mode_map, key, cmd) end define_key :isearch_mode_map, (conf.isearch_occur_key || '\C-o'), :langhelp_isearch_occur define_key :global_map, conf.langhelp_key, :langhelp if conf.langhelp_key end |
#defun_langhelp_occur ⇒ Object
766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 |
# File 'lib/el4r/emacsruby/langhelp.rb', line 766 def defun_langhelp_occur if conf.occur_by_grep defun(:langhelp_occur, :interactive=>true, :docstring=>"Show all lines in the current buffer containing a match for isearch.") do |re| occur_buf = generate_new_buffer "*langhelp occur /#{re}/*" re = re + "|<<<.+>>>" let(:display_buffer_function, :switch_to_buffer) do shell_command_on_region(point_min, point_max, "grep -E -i -- #{re.dump}", occur_buf) switch_to_buffer occur_buf end end else defun(:langhelp_occur, :interactive=>true, :docstring=>"Show all lines in the current buffer containing a match for isearch.") do |re| occur_buf = generate_new_buffer "*langhelp occur [#{re}]*" re = re + "\\|<<<.+>>>" empty = true with(:save_excursion) do while re_search_forward(re, nil, true) empty = false line = thing_at_point :line with(:with_current_buffer, occur_buf) do insert line end end end unless empty switch_to_buffer occur_buf goto_char point_min end end end end |
#defun_langhelp_setup_index_buffer ⇒ Object
550 551 552 553 554 555 556 557 558 559 560 |
# File 'lib/el4r/emacsruby/langhelp.rb', line 550 def defun_langhelp_setup_index_buffer defun(:langhelp_setup_index_buffer) do index_content = conf.lang.sort.map {|lang, params| %Q!# (lh-language-index "#{lang}")\n! }.join newbuf(:name=>INDEX_BUFFER, :contents=>index_content, :point=>1) { elvar. = nil } end end |
#defun_langhelp_update(x) ⇒ Object
321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 |
# File 'lib/el4r/emacsruby/langhelp.rb', line 321 def defun_langhelp_update(x) defun(:langhelp_update, :interactive=>true) do langhelprc = x[:langhelprc] || File.("~/.langhelp/config") @conf = ConfigScript.new langhelprc @use_frame = elvar.window_system && !@conf[:NO_FRAME] conf.lang.each do |name, params| Array[params].flatten.each do |x| case x when Hash if x[:Info] info_file = x[:Info] dir = File.dirname(File.(info_file)) add_to_list :Info_directory_list, dir else command_klass, t = x.find{|k,v| k.to_s =~ %r/^[A-Z]/ and v == true } command_klass = command_klass.to_s if command_klass cmd = command_klass.downcase FindXXX.run(:name=>cmd, :cmd=>(x[:cmd] || cmd)) end end end end end @alias2base = Hash.new{|hash,k|k} conf.aliases.each do |base, aliases| aliases.each do |ali| @alias2base[ali] = base end end end end |
#key_binding_default ⇒ Object
192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 |
# File 'lib/el4r/emacsruby/langhelp.rb', line 192 def key_binding_default { ##### [key_binding] 'n' => :next_line, 'p' => :previous_line, ## vi-like cursor movement 'j' => :next_line, 'k' => :previous_line, ## follow the link # [EVAL IT] (describe-function 'lh-goto-link) # [EVAL IT] (describe-function 'lh-goto-link-centering) # [EVAL IT] (describe-function 'lh-goto-link-edit) 'l' => :lh_goto_link, '\C-m' => :lh_goto_link, ';' => :lh_goto_link_centering, 'C' => :lh_goto_link_centering, 'L' => :lh_goto_link_centering, 'o' => :lh_goto_link_edit, ## Kill help buffer # [EVAL IT] (describe-function 'lh-kill-link) 'D' => :lh_kill_link, 'K' => :lh_kill_link, ## Restore window configuration before langhelp-call. '\C-c\C-c' => :winconf_pop, 'h' => :winconf_pop, ## scroll the langhelp buffer ' ' => :scroll_up, 'b' => :scroll_down, '/' => :isearch_forward, 's' => :isearch_forward, 'g' => :beginning_of_buffer, ## scroll help buffer (under the langhelp buffer) # [EVAL IT] (describe-function 'scroll-other-window) # [EVAL IT] (describe-function 'scroll-other-window-down) 'v' => :scroll_other_window, 'c' => :scroll_other_window_down, ## Update langhelp buffer # [EVAL IT] (describe-function 'langhelp-revert-buffer) 'R' => :langhelp_revert_buffer, ## bm.el : buffer bookmark. # [EVAL IT] (describe-function 'bm-toggle) # [EVAL IT] (describe-function 'bm-previous) # [EVAL IT] (describe-function 'bm-next) 'm' => :bm_toggle, 'u' => :bm_toggle, 'P' => :bm_previous, 'N' => :bm_next, ## show full index # [EVAL IT] (describe-function 'langhelp-switch-to-index-buffer) 'd' => :langhelp_switch_to_index_buffer, ## narrowing # [EVAL IT] (describe-function 'langhelp-toggle-narrowing) '\C-c\C-n' => :langhelp_toggle_narrowing, ## exclude # [EVAL IT] (describe-function 'flush-lines) 'V' => :flush_lines_whole_buffer, 'G' => :keep_lines_whole_buffer, ##### [/key_binding] } end |
#narrowing? ⇒ Boolean
803 804 805 |
# File 'lib/el4r/emacsruby/langhelp.rb', line 803 def narrowing? buffer_size != point_max-1 or point_min != 1 end |
#real_mmode ⇒ Object
491 492 493 |
# File 'lib/el4r/emacsruby/langhelp.rb', line 491 def real_mmode @alias2base[symbol_name(getq(:major_mode)).sub(/-mode/, '')] end |
#set_tab_width ⇒ Object
356 357 358 359 360 361 362 363 364 365 |
# File 'lib/el4r/emacsruby/langhelp.rb', line 356 def set_tab_width tw = conf[:TAB_WIDTH] if tw elvar.tab_width = if tw <= 0 frame_width + tw else tw end end end |
#set_which_func ⇒ Object
368 369 370 371 372 373 |
# File 'lib/el4r/emacsruby/langhelp.rb', line 368 def set_which_func if locate_library "which-func" el_require :which_func add_to_list :which_func_modes, :langhelp_menu_mode end end |
#setup_font_lock ⇒ Object
299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 |
# File 'lib/el4r/emacsruby/langhelp.rb', line 299 def setup_font_lock el4r_lisp_eval <<-'EOL' (progn (setq langhelp-font-lock-keywords (list '("^[^\n]+\\((lh[^\n]+)\\)$" 1 langhelp-sexp-face) '("^[^\n]+<<.+>>[^\n]*$" 0 langhelp-title-face) )) (make-local-variable 'font-lock-defaults) (setq font-lock-defaults '((langhelp-font-lock-keywords) t nil)) (make-local-variable 'font-lock-keywords) (setq font-lock-keywords langhelp-font-lock-keywords) (turn-on-font-lock) ) EOL # ' end |
#setup_man ⇒ Object
648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 |
# File 'lib/el4r/emacsruby/langhelp.rb', line 648 def setup_man defalias :lh_man, :man defvar :lh_man_line defadvice(:Man_notify_when_ready, :around, :lh_man, :activate) do if elvar.lh_man_line display_result(:line=>elvar.lh_man_line) do switch_to_buffer elvar.man_buffer end elvar.lh_man_line = nil else ad_do_it end end end |
#setup_w3m ⇒ Object
697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 |
# File 'lib/el4r/emacsruby/langhelp.rb', line 697 def setup_w3m ## for speed el4r_lisp_eval %q( (defun w3m-list-buffer-names () (mapcar (lambda (b) (buffer-name b)) (w3m-list-buffers))) ) byte_compile :w3m_list_buffer_names @w3m_buffers_cache = {} defun(:langhelp_w3m_fontify_after_hook0) do b = buffer_name url = abbreviate_url @w3m_buffers_cache[b] = [url,b] end add_hook :w3m_fontify_after_hook, :langhelp_w3m_fontify_after_hook0 end |