langhelp 0.9.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Changes +2530 -0
- data/bin/mklanghelp +50 -0
- data/data/langhelp/config.sample +889 -0
- data/files +39 -0
- data/graphviz-dot.jpg +0 -0
- data/langhelp.en.html +409 -0
- data/langhelp.en.rd +390 -0
- data/langhelp.ja.html +524 -0
- data/langhelp.ja.rd +487 -0
- data/lib/el4r/emacsruby/autoload/50langhelp.rb +2 -0
- data/lib/el4r/emacsruby/langhelp.rb +864 -0
- data/lib/el4r/emacsruby/test-langhelp.rb +300 -0
- data/lib/langhelp/langhelp-base.rb +649 -0
- data/lib/langhelp/langhelp-sub.rb +1023 -0
- data/lib/langhelp/lh_lua.rb +25 -0
- data/lib/langhelp/lh_perl.rb +112 -0
- data/lib/langhelp/lh_php.rb +34 -0
- data/lib/langhelp/lh_python.rb +31 -0
- data/lib/langhelp/lh_ruby.rb +400 -0
- data/lib/langhelp/mklanghelp.rb +140 -0
- data/lib/langhelp/parse-info.rb +145 -0
- data/ri.jpg +0 -0
- data/setup.rb +1551 -0
- data/test/a_classes.lst +2 -0
- data/test/a_methods.lst +2 -0
- data/test/b_classes.lst +2 -0
- data/test/b_methods.lst +2 -0
- data/test/c_methods.lst +4 -0
- data/test/common.rb +15 -0
- data/test/d_methods.lst +4 -0
- data/test/langhelp.e +566 -0
- data/test/ruby.e +3 -0
- data/test/tagify01-before.html +11 -0
- data/test/tagify02-before.html +11 -0
- data/test/test-base.rb +538 -0
- data/test/test-command.rb +92 -0
- data/test/test-parse-info.rb +175 -0
- data/test/test-ruby.rb +242 -0
- data/test/testdoc.rd +6 -0
- metadata +84 -0
@@ -0,0 +1,864 @@
|
|
1
|
+
# -*- el4r -*-
|
2
|
+
# langhelp.rb - The EmacsRuby part of langhelp
|
3
|
+
#
|
4
|
+
# Copyright (C) 2005,2006 rubikitch <rubikitch@ruby-lang.org>
|
5
|
+
# Version: $Id: langhelp.rb 1363 2006-09-04 01:31:05Z rubikitch $
|
6
|
+
|
7
|
+
# This program is free software; you can redistribute it and/or modify
|
8
|
+
# it under the terms of the GNU General Public License as published by
|
9
|
+
# the Free Software Foundation; either version 2 of the License, or
|
10
|
+
# (at your option) any later version.
|
11
|
+
# This program is distributed in the hope that it will be useful,
|
12
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14
|
+
# GNU General Public License for more details.
|
15
|
+
# You should have received a copy of the GNU General Public License
|
16
|
+
# along with this program; if not, write to the Free Software
|
17
|
+
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
18
|
+
|
19
|
+
require 'langhelp/langhelp-sub'
|
20
|
+
|
21
|
+
module LangHelp
|
22
|
+
|
23
|
+
module DisplayResult
|
24
|
+
def search_line(line)
|
25
|
+
search_forward "\n#{line}\n", nil, true and previous_line 1
|
26
|
+
end
|
27
|
+
|
28
|
+
def search_anchor(anchor)
|
29
|
+
goto_char 1
|
30
|
+
search_forward(format(elvar.ee_anchor_format,anchor), nil, true) and forward_line 0
|
31
|
+
end
|
32
|
+
|
33
|
+
def flash_line
|
34
|
+
if fboundp :make_overlay
|
35
|
+
ovl = make_overlay point_at_bol, point_at_eol
|
36
|
+
duration = 1
|
37
|
+
overlay_put ovl, :face, :highlight
|
38
|
+
run_at_time duration, nil, :delete_overlay, ovl
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def display_result_buffer(buf, pt, x)
|
43
|
+
# display_buffer buf
|
44
|
+
one_window_p and split_window
|
45
|
+
let(:pop_up_windows, true) { pop_to_buffer buf }
|
46
|
+
goto_char pt
|
47
|
+
|
48
|
+
recenter((elvar.langhelp_centering || x[:centering]) ? [1] : 0)
|
49
|
+
if x[:flash] || elvar.langhelp_flash
|
50
|
+
flash_line
|
51
|
+
end
|
52
|
+
|
53
|
+
sit_for 0
|
54
|
+
other_window 1 unless elvar.langhelp_edit
|
55
|
+
end
|
56
|
+
|
57
|
+
# keyword of x: :line / :anchor
|
58
|
+
def display_result(x={})
|
59
|
+
buf = nil
|
60
|
+
pt = nil
|
61
|
+
with(:save_window_excursion) do
|
62
|
+
yield
|
63
|
+
buf = current_buffer
|
64
|
+
if x[:line]
|
65
|
+
goto_char 1
|
66
|
+
# TODO: write test for lineno
|
67
|
+
if Fixnum === x[:line]
|
68
|
+
forward_line x[:line]-1
|
69
|
+
else
|
70
|
+
search_line x[:line]
|
71
|
+
end
|
72
|
+
elsif x[:anchor]
|
73
|
+
search_anchor x[:anchor]
|
74
|
+
elsif x[:preserve]
|
75
|
+
#
|
76
|
+
elsif !x[:w3m]
|
77
|
+
goto_char 1
|
78
|
+
end
|
79
|
+
pt = point
|
80
|
+
end
|
81
|
+
display_result_buffer buf, pt, x
|
82
|
+
buf
|
83
|
+
end
|
84
|
+
|
85
|
+
end
|
86
|
+
|
87
|
+
class FindXXX < ElApp
|
88
|
+
def initialize(x={})
|
89
|
+
name = x[:name]
|
90
|
+
cmd = x[:cmd]
|
91
|
+
|
92
|
+
# lh_sh is defined at (view-fline buffer-file-name '(4988 " defun(:lh_sh" "_view_functions\n"))
|
93
|
+
defun("lh-#{name}") do |arg|
|
94
|
+
lh_sh "#{cmd} #{arg.dump}", arg
|
95
|
+
end
|
96
|
+
|
97
|
+
meth = "override_#{name}"
|
98
|
+
respond_to? meth and __send__ meth
|
99
|
+
end
|
100
|
+
|
101
|
+
include DisplayResult
|
102
|
+
|
103
|
+
def override_ri
|
104
|
+
if locate_library "ri-ruby"
|
105
|
+
el_load "ri-ruby"
|
106
|
+
defun("lh-ri") do |x|
|
107
|
+
display_result {
|
108
|
+
ri x
|
109
|
+
unless fboundp :with_displaying_help_buffer # for FSF Emacs
|
110
|
+
other_window 1
|
111
|
+
end
|
112
|
+
}
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
def override_test0
|
118
|
+
# Mock-up for unit-test
|
119
|
+
defun("lh-test0") do |x|
|
120
|
+
newbuf(:name=>"test0", :contents=>"0\n", :display=>:pop)
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
class LangHelpInternal < ElApp
|
126
|
+
def initialize(x)
|
127
|
+
@mmode = x[:major_mode]
|
128
|
+
@dir = x[:datadir]
|
129
|
+
@efile = "#{@dir}/#{@mmode}.e"
|
130
|
+
@header = "#{@dir}/#{@mmode}-header.e"
|
131
|
+
@encoding = x[:encoding] || :euc_jp
|
132
|
+
@buffer_ctime = 0
|
133
|
+
@use_frame = x[:use_frame]
|
134
|
+
end
|
135
|
+
attr_reader :mmode, :dir, :efile, :header, :buf
|
136
|
+
|
137
|
+
def create_buffer
|
138
|
+
@buffer_ctime = Time.now
|
139
|
+
@buf = newbuf(:name => "*langhelp:#{mmode}*") do
|
140
|
+
let(:coding_system_for_read, @encoding) do
|
141
|
+
if File.exist?(header)
|
142
|
+
insert_file_contents header
|
143
|
+
goto_char point_max
|
144
|
+
insert "\n\n"
|
145
|
+
end
|
146
|
+
insert_file_contents efile
|
147
|
+
goto_char 1
|
148
|
+
end
|
149
|
+
|
150
|
+
cd dir
|
151
|
+
langhelp_menu_mode
|
152
|
+
|
153
|
+
# I do not know why `hack_local_variables' in langhelp_menu_mode does not work well.
|
154
|
+
hack_local_variables
|
155
|
+
with(:save_excursion) { lh_imenu_create_index }
|
156
|
+
end
|
157
|
+
@buf
|
158
|
+
|
159
|
+
end
|
160
|
+
|
161
|
+
def header_is_newer_than_buffer(file=@header)
|
162
|
+
File.mtime(file) > @buffer_ctime
|
163
|
+
end
|
164
|
+
|
165
|
+
def selbuf(buf)
|
166
|
+
if @use_frame
|
167
|
+
switch_to_buffer(buf)
|
168
|
+
bury_buffer(buf)
|
169
|
+
else
|
170
|
+
pop_to_buffer(buf)
|
171
|
+
end
|
172
|
+
end
|
173
|
+
|
174
|
+
def setup_buffer
|
175
|
+
if File.exist?(efile)
|
176
|
+
if @use_frame
|
177
|
+
langhelp_select_frame
|
178
|
+
else
|
179
|
+
winconf_push
|
180
|
+
end
|
181
|
+
if buffer_live_p(@buf) and not header_is_newer_than_buffer
|
182
|
+
selbuf @buf
|
183
|
+
else
|
184
|
+
selbuf create_buffer
|
185
|
+
end
|
186
|
+
yield(@buf)
|
187
|
+
end
|
188
|
+
end
|
189
|
+
end # /LangHelpInternal
|
190
|
+
|
191
|
+
class LangHelp < ElApp
|
192
|
+
def key_binding_default
|
193
|
+
{
|
194
|
+
##### [key_binding]
|
195
|
+
'n' => :next_line,
|
196
|
+
'p' => :previous_line,
|
197
|
+
|
198
|
+
## vi-like cursor movement
|
199
|
+
'j' => :next_line,
|
200
|
+
'k' => :previous_line,
|
201
|
+
|
202
|
+
## follow the link
|
203
|
+
# [EVAL IT] (describe-function 'lh-goto-link)
|
204
|
+
# [EVAL IT] (describe-function 'lh-goto-link-centering)
|
205
|
+
# [EVAL IT] (describe-function 'lh-goto-link-edit)
|
206
|
+
'l' => :lh_goto_link,
|
207
|
+
'\C-m' => :lh_goto_link,
|
208
|
+
';' => :lh_goto_link_centering,
|
209
|
+
'C' => :lh_goto_link_centering,
|
210
|
+
'L' => :lh_goto_link_centering,
|
211
|
+
'o' => :lh_goto_link_edit,
|
212
|
+
## Kill help buffer
|
213
|
+
# [EVAL IT] (describe-function 'lh-kill-link)
|
214
|
+
'D' => :lh_kill_link,
|
215
|
+
'K' => :lh_kill_link,
|
216
|
+
|
217
|
+
|
218
|
+
## Restore window configuration before langhelp-call.
|
219
|
+
'\C-c\C-c' => :winconf_pop,
|
220
|
+
'h' => :winconf_pop,
|
221
|
+
|
222
|
+
## scroll the langhelp buffer
|
223
|
+
' ' => :scroll_up,
|
224
|
+
'b' => :scroll_down,
|
225
|
+
|
226
|
+
'/' => :isearch_forward,
|
227
|
+
's' => :isearch_forward,
|
228
|
+
'g' => :beginning_of_buffer,
|
229
|
+
|
230
|
+
## scroll help buffer (under the langhelp buffer)
|
231
|
+
# [EVAL IT] (describe-function 'scroll-other-window)
|
232
|
+
# [EVAL IT] (describe-function 'scroll-other-window-down)
|
233
|
+
'v' => :scroll_other_window,
|
234
|
+
'c' => :scroll_other_window_down,
|
235
|
+
|
236
|
+
## Update langhelp buffer
|
237
|
+
# [EVAL IT] (describe-function 'langhelp-revert-buffer)
|
238
|
+
'R' => :langhelp_revert_buffer,
|
239
|
+
|
240
|
+
## bm.el : buffer bookmark.
|
241
|
+
# [EVAL IT] (describe-function 'bm-toggle)
|
242
|
+
# [EVAL IT] (describe-function 'bm-previous)
|
243
|
+
# [EVAL IT] (describe-function 'bm-next)
|
244
|
+
'm' => :bm_toggle,
|
245
|
+
'u' => :bm_toggle,
|
246
|
+
'P' => :bm_previous,
|
247
|
+
'N' => :bm_next,
|
248
|
+
|
249
|
+
## show full index
|
250
|
+
# [EVAL IT] (describe-function 'langhelp-switch-to-index-buffer)
|
251
|
+
'd' => :langhelp_switch_to_index_buffer,
|
252
|
+
|
253
|
+
## narrowing
|
254
|
+
# [EVAL IT] (describe-function 'langhelp-toggle-narrowing)
|
255
|
+
'\C-c\C-n' => :langhelp_toggle_narrowing,
|
256
|
+
|
257
|
+
## exclude
|
258
|
+
# [EVAL IT] (describe-function 'flush-lines)
|
259
|
+
'V' => :flush_lines_whole_buffer,
|
260
|
+
'G' => :keep_lines_whole_buffer,
|
261
|
+
|
262
|
+
##### [/key_binding]
|
263
|
+
}
|
264
|
+
end
|
265
|
+
|
266
|
+
attr :conf
|
267
|
+
|
268
|
+
def initialize(x={})
|
269
|
+
el_require :info
|
270
|
+
el_require :cl
|
271
|
+
funcall :put, :ee_anchor_format, :safe_local_variable, :stringp
|
272
|
+
define_faces
|
273
|
+
defun_langhelp_update x
|
274
|
+
langhelp_update
|
275
|
+
|
276
|
+
defun_langhelp_menu_mode
|
277
|
+
defun_langhelp_setup_index_buffer
|
278
|
+
setup_man
|
279
|
+
setup_w3m
|
280
|
+
defun_langhelp_occur
|
281
|
+
langhelp_setup_index_buffer
|
282
|
+
|
283
|
+
defalias :lh, :progn
|
284
|
+
end
|
285
|
+
|
286
|
+
def define_faces
|
287
|
+
el4r_lisp_eval <<-EOL
|
288
|
+
(progn
|
289
|
+
(defface langhelp-sexp-face '((t (:foreground "SteelBlue" :underline t))) nil)
|
290
|
+
(defface langhelp-title-face '((t (:background "white" :foreground "black"))) nil)
|
291
|
+
(setq langhelp-sexp-face 'langhelp-sexp-face)
|
292
|
+
|
293
|
+
(setq langhelp-title-face 'langhelp-title-face)
|
294
|
+
)
|
295
|
+
EOL
|
296
|
+
|
297
|
+
end
|
298
|
+
|
299
|
+
def setup_font_lock
|
300
|
+
el4r_lisp_eval <<-'EOL'
|
301
|
+
(progn
|
302
|
+
(setq langhelp-font-lock-keywords
|
303
|
+
(list
|
304
|
+
'("^[^\n]+\\((lh[^\n]+)\\)$"
|
305
|
+
1 langhelp-sexp-face)
|
306
|
+
'("^[^\n]+<<.+>>[^\n]*$"
|
307
|
+
0 langhelp-title-face)
|
308
|
+
))
|
309
|
+
|
310
|
+
(make-local-variable 'font-lock-defaults)
|
311
|
+
(setq font-lock-defaults '((langhelp-font-lock-keywords) t nil))
|
312
|
+
(make-local-variable 'font-lock-keywords)
|
313
|
+
(setq font-lock-keywords langhelp-font-lock-keywords)
|
314
|
+
(turn-on-font-lock)
|
315
|
+
)
|
316
|
+
EOL
|
317
|
+
# '
|
318
|
+
end
|
319
|
+
|
320
|
+
INDEX_BUFFER = "*langhelp index*"
|
321
|
+
def defun_langhelp_update(x)
|
322
|
+
defun(:langhelp_update, :interactive=>true) do
|
323
|
+
langhelprc = x[:langhelprc] || File.expand_path("~/.langhelp/config")
|
324
|
+
@conf = ConfigScript.new langhelprc
|
325
|
+
@use_frame = elvar.window_system && !@conf[:NO_FRAME]
|
326
|
+
|
327
|
+
conf.lang.each do |name, params|
|
328
|
+
Array[params].flatten.each do |x|
|
329
|
+
case x
|
330
|
+
when Hash
|
331
|
+
if x[:Info]
|
332
|
+
info_file = x[:Info]
|
333
|
+
dir = File.dirname(File.expand_path(info_file))
|
334
|
+
add_to_list :Info_directory_list, dir
|
335
|
+
else
|
336
|
+
command_klass, t = x.find{|k,v| k.to_s =~ %r/^[A-Z]/ and v == true }
|
337
|
+
command_klass = command_klass.to_s
|
338
|
+
if command_klass
|
339
|
+
cmd = command_klass.downcase
|
340
|
+
FindXXX.run(:name=>cmd, :cmd=>(x[:cmd] || cmd))
|
341
|
+
end
|
342
|
+
end
|
343
|
+
end
|
344
|
+
end
|
345
|
+
end
|
346
|
+
|
347
|
+
@alias2base = Hash.new{|hash,k|k}
|
348
|
+
conf.aliases.each do |base, aliases|
|
349
|
+
aliases.each do |ali|
|
350
|
+
@alias2base[ali] = base
|
351
|
+
end
|
352
|
+
end
|
353
|
+
end
|
354
|
+
end
|
355
|
+
|
356
|
+
def set_tab_width
|
357
|
+
tw = conf[:TAB_WIDTH]
|
358
|
+
if tw
|
359
|
+
elvar.tab_width = if tw <= 0
|
360
|
+
frame_width + tw
|
361
|
+
else
|
362
|
+
tw
|
363
|
+
end
|
364
|
+
end
|
365
|
+
end
|
366
|
+
|
367
|
+
|
368
|
+
def set_which_func
|
369
|
+
if locate_library "which-func"
|
370
|
+
el_require :which_func
|
371
|
+
add_to_list :which_func_modes, :langhelp_menu_mode
|
372
|
+
end
|
373
|
+
end
|
374
|
+
|
375
|
+
def defun_langhelp_menu_mode
|
376
|
+
set_which_func
|
377
|
+
defvar(:ee_anchor_format, "<<%s>>")
|
378
|
+
|
379
|
+
defvar(:langhelp_revert_buffer_function, nil)
|
380
|
+
define_derived_mode(:langhelp_menu_mode, :fundamental_mode, "LH",
|
381
|
+
"Major mode for selecting a langhelp link.") do
|
382
|
+
setup_font_lock
|
383
|
+
make_local_variable :langhelp_revert_buffer_function
|
384
|
+
elvar.truncate_lines = true
|
385
|
+
make_local_variable :outline_regexp
|
386
|
+
elvar.outline_regexp = '####\|# Node:'
|
387
|
+
make_local_variable :kill_whole_line
|
388
|
+
elvar.kill_whole_line = true
|
389
|
+
elvar.imenu_create_index_function = :lh_imenu_create_index
|
390
|
+
elvar.header_line_format = el4r_lisp_eval %('(which-func-mode ("" which-func-format))) # '
|
391
|
+
set_tab_width
|
392
|
+
which_func_mode 1 if fboundp :which_func_mode
|
393
|
+
hl_line_mode 1 if fboundp :hl_line_mode
|
394
|
+
end
|
395
|
+
|
396
|
+
suppress_keymap elvar.langhelp_menu_mode_map
|
397
|
+
key_binding = key_binding_default.update(conf[:KEY_BINDING] || {})
|
398
|
+
key_binding.each do |key, cmd|
|
399
|
+
define_key(:langhelp_menu_mode_map, key, cmd)
|
400
|
+
end
|
401
|
+
define_key :isearch_mode_map, (conf.isearch_occur_key || '\C-o'), :langhelp_isearch_occur
|
402
|
+
define_key :global_map, conf.langhelp_key, :langhelp if conf.langhelp_key
|
403
|
+
|
404
|
+
end
|
405
|
+
|
406
|
+
defun(:lh_goto_link, :interactive=>true,
|
407
|
+
:docstring=>"Follow link in this line and put point on screen top.
|
408
|
+
Internally eval sexp at the EOL.") do
|
409
|
+
b = current_buffer
|
410
|
+
end_of_line
|
411
|
+
backward_sexp
|
412
|
+
sexp = funcall :read, current_buffer
|
413
|
+
beginning_of_line
|
414
|
+
pt = point
|
415
|
+
funcall :eval, sexp
|
416
|
+
end
|
417
|
+
|
418
|
+
defvar(:langhelp_centering, nil)
|
419
|
+
defvar(:langhelp_flash, nil)
|
420
|
+
defun(:lh_goto_link_centering, :interactive=>true,
|
421
|
+
:docstring=>"Follow link in this line and center point in window.") do
|
422
|
+
let(:langhelp_centering, true,
|
423
|
+
:langhelp_flash, true) do
|
424
|
+
lh_goto_link
|
425
|
+
end
|
426
|
+
end
|
427
|
+
|
428
|
+
defvar(:langhelp_edit, nil)
|
429
|
+
defun(:lh_goto_link_edit, :interactive=>true,
|
430
|
+
:docstring=>"Follow link in this line and select the help window to edit.") do
|
431
|
+
let(:langhelp_edit, true,
|
432
|
+
:langhelp_centering, true) do
|
433
|
+
lh_goto_link
|
434
|
+
end
|
435
|
+
end
|
436
|
+
|
437
|
+
defun(:lh_kill_link, :interactive=>true,
|
438
|
+
:docstring=>"Kill the help window buffer.") do
|
439
|
+
with(:save_selected_window) do
|
440
|
+
other_window 1
|
441
|
+
kill_this_buffer
|
442
|
+
end
|
443
|
+
end
|
444
|
+
|
445
|
+
el4r_lisp_eval %q(
|
446
|
+
(defun lh-imenu-create-index ()
|
447
|
+
(goto-char 1)
|
448
|
+
(let ((search-re (format ee-anchor-format "\\\\(.+\\\\)"))
|
449
|
+
alist a p)
|
450
|
+
(while (re-search-forward search-re nil t)
|
451
|
+
(setq a (match-string 1)
|
452
|
+
p (match-beginning 0))
|
453
|
+
(unless (string= a "%s")
|
454
|
+
(setq alist (cons (cons a p) alist))))
|
455
|
+
(setq imenu--index-alist alist))
|
456
|
+
nil))
|
457
|
+
|
458
|
+
import_function :byte_compile
|
459
|
+
byte_compile :lh_imenu_create_index
|
460
|
+
|
461
|
+
defun(:langhelp_switch_to_index_buffer, :interactive=>true,
|
462
|
+
:docstring=>"Switch to *langhelp index* buffer.") do
|
463
|
+
unless get_buffer INDEX_BUFFER
|
464
|
+
langhelp_setup_index_buffer
|
465
|
+
end
|
466
|
+
switch_to_buffer INDEX_BUFFER
|
467
|
+
goto_char 1
|
468
|
+
end
|
469
|
+
|
470
|
+
# todo EGREP
|
471
|
+
defun(:flush_lines_whole_buffer,
|
472
|
+
:docstring=>"Delete lines containing matches for REGEXP.",
|
473
|
+
:interactive=>lambda{keep_lines_read_args("Flush lines (containing match for regexp): ")}) do |re|
|
474
|
+
with(:save_restriction) do
|
475
|
+
widen
|
476
|
+
flush_lines re, 1, point_max_marker
|
477
|
+
end
|
478
|
+
end
|
479
|
+
|
480
|
+
defun(:keep_lines_whole_buffer,
|
481
|
+
:docstring=>"Delete all lines except those containing matches for REGEXP.",
|
482
|
+
:interactive=>lambda{keep_lines_read_args("Keep lines (containing match for regexp): ")}) do |re|
|
483
|
+
with(:save_restriction) do
|
484
|
+
widen
|
485
|
+
keep_lines re, 1, point_max_marker
|
486
|
+
end
|
487
|
+
end
|
488
|
+
|
489
|
+
|
490
|
+
|
491
|
+
def real_mmode
|
492
|
+
@alias2base[symbol_name(getq(:major_mode)).sub(/-mode/, '')]
|
493
|
+
end
|
494
|
+
|
495
|
+
defun(:langhelp, :interactive=>"p",
|
496
|
+
:docstring=>"Open the langhelp buffer according to major-mode and prepare isearch.
|
497
|
+
With prefix arg, open the *langhelp index* buffer instead of major-mode's langhelp buffer.") do |narg|
|
498
|
+
# mmode = symbol_name(getq(:major_mode)).sub(/-mode/, '').gsub(/-/,'_')
|
499
|
+
mmode = real_mmode
|
500
|
+
if narg == 16
|
501
|
+
langhelp_at_point
|
502
|
+
elsif [1,nil].include?(narg) and conf.lang[mmode]
|
503
|
+
i = LangHelpInternal.new(:major_mode=>mmode, :datadir=>conf[:LANGHELP_HOME], :encoding=>conf[:ENCODING], :use_frame=>@use_frame)
|
504
|
+
i.setup_buffer do
|
505
|
+
isearch_forward
|
506
|
+
end
|
507
|
+
else
|
508
|
+
if @use_frame
|
509
|
+
langhelp_select_frame
|
510
|
+
else
|
511
|
+
winconf_push
|
512
|
+
end
|
513
|
+
langhelp_switch_to_index_buffer
|
514
|
+
let(:migemo_isearch_enable_p, nil) { isearch_forward }
|
515
|
+
end
|
516
|
+
end
|
517
|
+
|
518
|
+
defun(:langhelp_at_point, :interactive=>true,
|
519
|
+
:docstring=>"Open the langhelp buffer according to major-mode and point.") do
|
520
|
+
word = sexp_at_point.to_s.gsub(/_/, '[_-]')
|
521
|
+
mmode = real_mmode
|
522
|
+
i = LangHelpInternal.new(:major_mode=>mmode, :datadir=>conf[:LANGHELP_HOME], :encoding=>conf[:ENCODING], :use_frame=>@use_frame)
|
523
|
+
i.setup_buffer do
|
524
|
+
re = '\b' + word # + '\b'
|
525
|
+
langhelp_occur re
|
526
|
+
end
|
527
|
+
end
|
528
|
+
|
529
|
+
defun(:langhelp_revert_buffer_default, :interactive=>true,
|
530
|
+
:docstring=>"Reread info of this langhelp buffer.") do
|
531
|
+
# TODO: do not use buffer_name
|
532
|
+
mmode = buffer_name.scan(/\*langhelp:(.+)\*/).to_s
|
533
|
+
p = point
|
534
|
+
i = LangHelpInternal.new(:major_mode=>mmode, :datadir=>conf[:LANGHELP_HOME], :encoding=>conf[:ENCODING])
|
535
|
+
i.create_buffer
|
536
|
+
goto_char p
|
537
|
+
end
|
538
|
+
|
539
|
+
defun(:langhelp_revert_buffer, :interactive=>true,
|
540
|
+
:docstring=>"Reread and update this langhelp buffer.
|
541
|
+
If `langhelp-revert-buffer-function' is specified, use it.
|
542
|
+
Otherwise `langhelp-revert-buffer-default' is used.") do
|
543
|
+
if elvar.langhelp_revert_buffer_function
|
544
|
+
el4r_lisp_eval %q((funcall langhelp-revert-buffer-function))
|
545
|
+
else
|
546
|
+
langhelp_revert_buffer_default
|
547
|
+
end
|
548
|
+
end
|
549
|
+
|
550
|
+
def defun_langhelp_setup_index_buffer
|
551
|
+
defun(:langhelp_setup_index_buffer) do
|
552
|
+
index_content = conf.lang.sort.map {|lang, params|
|
553
|
+
%Q!# (lh-language-index "#{lang}")\n!
|
554
|
+
}.join
|
555
|
+
newbuf(:name=>INDEX_BUFFER, :contents=>index_content, :point=>1) {
|
556
|
+
langhelp_menu_mode
|
557
|
+
elvar.imenu_create_index_function = nil
|
558
|
+
}
|
559
|
+
end
|
560
|
+
end
|
561
|
+
|
562
|
+
defun(:lh_language_index,
|
563
|
+
:docstring=>"Open the LANG's langhelp index.") do |lang|
|
564
|
+
# TODO: do not use buffer_name
|
565
|
+
unless get_buffer "*langhelp:#{lang}*"
|
566
|
+
i = LangHelpInternal.new(:major_mode=>lang, :datadir=>conf[:LANGHELP_HOME], :encoding=>conf[:ENCODING])
|
567
|
+
i.create_buffer
|
568
|
+
end
|
569
|
+
switch_to_buffer "*langhelp:#{lang}*"
|
570
|
+
end
|
571
|
+
|
572
|
+
el4r_lisp_eval <<'EOL'
|
573
|
+
(defun langhelp-select-frame ()
|
574
|
+
(let ((get (lambda ()
|
575
|
+
(find-if (lambda (frame)
|
576
|
+
(equal (cdr (assq 'title (frame-parameters frame)))
|
577
|
+
"langhelp"))
|
578
|
+
(frame-list))))
|
579
|
+
(make (lambda ()
|
580
|
+
(if (boundp 'langhelp-frame-alist)
|
581
|
+
(make-frame `((title . "langhelp") ,@langhelp-frame-alist))
|
582
|
+
(make-frame '((title . "langhelp"))))))
|
583
|
+
(select (lambda (frm)
|
584
|
+
(select-frame frm)
|
585
|
+
(raise-frame frm)
|
586
|
+
(delete-other-windows))))
|
587
|
+
(funcall select (or (funcall get) (funcall make)))))
|
588
|
+
EOL
|
589
|
+
# `
|
590
|
+
|
591
|
+
include DisplayResult
|
592
|
+
|
593
|
+
defvar(:in_langhelp, nil)
|
594
|
+
defun(:__lh_ow) do |sexp|
|
595
|
+
let(:in_langhelp, true) do
|
596
|
+
display_result(:preserve=>true) do
|
597
|
+
funcall(:eval,sexp)
|
598
|
+
end
|
599
|
+
end
|
600
|
+
end
|
601
|
+
|
602
|
+
el4r_lisp_eval %(
|
603
|
+
(defmacro lh-ow (sexp)
|
604
|
+
"Eval SEXP and display result in other window."
|
605
|
+
`(--lh-ow ',sexp))) # '`
|
606
|
+
|
607
|
+
defun(:lh_sh,
|
608
|
+
:docstring=>"Hyperlink to the output of shell commands") do |command, line|
|
609
|
+
display_result(:line=>line) do
|
610
|
+
if get_buffer command
|
611
|
+
switch_to_buffer command
|
612
|
+
else
|
613
|
+
switch_to_buffer command
|
614
|
+
let(:coding_system_for_read, conf[:ENCODING],
|
615
|
+
:max_mini_window_height, 1) do
|
616
|
+
shell_command command, command
|
617
|
+
set_buffer command
|
618
|
+
#insert shell_command_to_string(command)
|
619
|
+
end
|
620
|
+
view_mode 1
|
621
|
+
end
|
622
|
+
end
|
623
|
+
end
|
624
|
+
|
625
|
+
|
626
|
+
defun(:lh_view, :interactive=>true,
|
627
|
+
:docstring=>"Hyperlink to text files. (view-mode)") do |line, filename|
|
628
|
+
display_result(:line=>line) do
|
629
|
+
view_file filename
|
630
|
+
end
|
631
|
+
end
|
632
|
+
|
633
|
+
defun(:lh_file, :interactive=>true,
|
634
|
+
:docstring=>"Hyperlink to text files.") do |line, filename|
|
635
|
+
display_result(:line=>line) do
|
636
|
+
find_file filename
|
637
|
+
end
|
638
|
+
end
|
639
|
+
|
640
|
+
defun(:lh_anchor, :interactive=>true,
|
641
|
+
:docstring=>"Hyperlink to anchors.") do |anchor, filename|
|
642
|
+
display_result(:anchor=>anchor) do
|
643
|
+
view_file filename
|
644
|
+
end
|
645
|
+
end
|
646
|
+
|
647
|
+
|
648
|
+
def setup_man
|
649
|
+
defalias :lh_man, :man
|
650
|
+
|
651
|
+
defvar :lh_man_line
|
652
|
+
defadvice(:Man_notify_when_ready, :around, :lh_man, :activate) do
|
653
|
+
if elvar.lh_man_line
|
654
|
+
display_result(:line=>elvar.lh_man_line) do
|
655
|
+
switch_to_buffer elvar.man_buffer
|
656
|
+
end
|
657
|
+
elvar.lh_man_line = nil
|
658
|
+
else
|
659
|
+
ad_do_it
|
660
|
+
end
|
661
|
+
end
|
662
|
+
|
663
|
+
end
|
664
|
+
|
665
|
+
defun("lh-man*", :docstring=>"Hyperlink to manpage.") do |line, manpage|
|
666
|
+
elvar.lh_man_line = line
|
667
|
+
man manpage
|
668
|
+
end
|
669
|
+
|
670
|
+
defun(:lh_info,
|
671
|
+
:docstring=>"Hyperlink to Info.") do |line, book|
|
672
|
+
let(:same_window_buffer_names,nil,
|
673
|
+
:same_window_regexps, nil) do
|
674
|
+
bufname = "*info*<langhelp>"
|
675
|
+
display_result(:line=>line) do
|
676
|
+
set_buffer(get_buffer_create(bufname))
|
677
|
+
Info_mode() unless elvar.major_mode.to_s == "Info-mode"
|
678
|
+
Info_goto_node(book)
|
679
|
+
end
|
680
|
+
end
|
681
|
+
end
|
682
|
+
|
683
|
+
|
684
|
+
|
685
|
+
defun(:lh_to, :interactive=>"sAnchor: ",
|
686
|
+
:docstring=>"Go to the anchor.") do |anchor|
|
687
|
+
winconf_push
|
688
|
+
search_anchor anchor
|
689
|
+
end
|
690
|
+
|
691
|
+
|
692
|
+
|
693
|
+
def abbreviate_url
|
694
|
+
abbreviate_file_name((elvar.w3m_current_url || '').sub(%r!^file://!,''))
|
695
|
+
end
|
696
|
+
|
697
|
+
def setup_w3m
|
698
|
+
## for speed
|
699
|
+
el4r_lisp_eval %q(
|
700
|
+
(defun w3m-list-buffer-names ()
|
701
|
+
(mapcar (lambda (b) (buffer-name b)) (w3m-list-buffers)))
|
702
|
+
)
|
703
|
+
byte_compile :w3m_list_buffer_names
|
704
|
+
|
705
|
+
@w3m_buffers_cache = {}
|
706
|
+
defun(:langhelp_w3m_fontify_after_hook0) do
|
707
|
+
b = buffer_name
|
708
|
+
url = abbreviate_url
|
709
|
+
@w3m_buffers_cache[b] = [url,b]
|
710
|
+
end
|
711
|
+
add_hook :w3m_fontify_after_hook, :langhelp_w3m_fontify_after_hook0
|
712
|
+
|
713
|
+
end
|
714
|
+
|
715
|
+
defun(:lh_w3m, :interactive=>true,
|
716
|
+
:docstring=>"Hyperlink to files in HTML.") do |line, filename|
|
717
|
+
display_result(:line=>line, :w3m=>true) do
|
718
|
+
el_require :w3m
|
719
|
+
filename.sub!(%r!file://!, '')
|
720
|
+
filename = abbreviate_file_name filename
|
721
|
+
filename, name_anchor = filename.split(/#/,2)
|
722
|
+
urlfile = w3m_expand_file_name_as_url filename
|
723
|
+
url, buf = w3m_list_buffer_names.to_a.map{|b|
|
724
|
+
unless @w3m_buffers_cache[b]
|
725
|
+
with(:with_current_buffer,b){
|
726
|
+
@w3m_buffers_cache[b] = [abbreviate_url, b]
|
727
|
+
}
|
728
|
+
end
|
729
|
+
@w3m_buffers_cache[b]
|
730
|
+
}.find {|url, buf|
|
731
|
+
url == filename
|
732
|
+
}
|
733
|
+
if buf
|
734
|
+
funcall :message, "reuse #{buf} buffer"
|
735
|
+
switch_to_buffer buf
|
736
|
+
else
|
737
|
+
w3m(urlfile, true)
|
738
|
+
end
|
739
|
+
if name_anchor
|
740
|
+
w3m_search_name_anchor name_anchor
|
741
|
+
else
|
742
|
+
goto_char 1
|
743
|
+
end
|
744
|
+
end
|
745
|
+
end
|
746
|
+
|
747
|
+
defun(:langhelp_isearch_occur, :interactive=>true,
|
748
|
+
:docstring=>"Invoke `langhelp-occur' from within isearch.") do
|
749
|
+
let(:case_fold_search, elvar.isearch_case_fold_search) do
|
750
|
+
|
751
|
+
re = if elvar.isearch_regexp
|
752
|
+
elvar.isearch_string
|
753
|
+
else
|
754
|
+
regexp_quote(elvar.isearch_string)
|
755
|
+
end
|
756
|
+
|
757
|
+
if elvar.major_mode.to_s == "langhelp-menu-mode"
|
758
|
+
isearch_exit
|
759
|
+
langhelp_occur re
|
760
|
+
else
|
761
|
+
occur re
|
762
|
+
end
|
763
|
+
end
|
764
|
+
end
|
765
|
+
|
766
|
+
def defun_langhelp_occur
|
767
|
+
if conf.occur_by_grep
|
768
|
+
defun(:langhelp_occur, :interactive=>true,
|
769
|
+
:docstring=>"Show all lines in the current buffer containing a match for isearch.") do |re|
|
770
|
+
occur_buf = generate_new_buffer "*langhelp occur /#{re}/*"
|
771
|
+
re = re + "|<<<.+>>>"
|
772
|
+
|
773
|
+
let(:display_buffer_function, :switch_to_buffer) do
|
774
|
+
shell_command_on_region(point_min, point_max, "grep -E -i -- #{re.dump}", occur_buf)
|
775
|
+
switch_to_buffer occur_buf
|
776
|
+
langhelp_menu_mode
|
777
|
+
end
|
778
|
+
end
|
779
|
+
else
|
780
|
+
defun(:langhelp_occur, :interactive=>true,
|
781
|
+
:docstring=>"Show all lines in the current buffer containing a match for isearch.") do |re|
|
782
|
+
occur_buf = generate_new_buffer "*langhelp occur [#{re}]*"
|
783
|
+
re = re + "\\|<<<.+>>>"
|
784
|
+
empty = true
|
785
|
+
with(:save_excursion) do
|
786
|
+
while re_search_forward(re, nil, true)
|
787
|
+
empty = false
|
788
|
+
line = thing_at_point :line
|
789
|
+
with(:with_current_buffer, occur_buf) do
|
790
|
+
insert line
|
791
|
+
end
|
792
|
+
end
|
793
|
+
end
|
794
|
+
unless empty
|
795
|
+
switch_to_buffer occur_buf
|
796
|
+
goto_char point_min
|
797
|
+
langhelp_menu_mode
|
798
|
+
end
|
799
|
+
end
|
800
|
+
end
|
801
|
+
end
|
802
|
+
|
803
|
+
def narrowing?
|
804
|
+
buffer_size != point_max-1 or point_min != 1
|
805
|
+
end
|
806
|
+
|
807
|
+
defun(:langhelp_narrow_to_section, :interactive=>true,
|
808
|
+
:docstring=>"Restrict showing in this buffer to the current section.") do
|
809
|
+
anchor_re = format(elvar.ee_anchor_format, '\(.+\)')
|
810
|
+
s, e = nil
|
811
|
+
with(:save_excursion) do
|
812
|
+
end_of_line
|
813
|
+
re_search_backward(anchor_re, nil, true)
|
814
|
+
s = point
|
815
|
+
end_of_line
|
816
|
+
if re_search_forward(anchor_re, nil, true)
|
817
|
+
beginning_of_line
|
818
|
+
else
|
819
|
+
goto_char point_max
|
820
|
+
end
|
821
|
+
e = point
|
822
|
+
end
|
823
|
+
|
824
|
+
narrow_to_region s, e
|
825
|
+
end
|
826
|
+
|
827
|
+
defun(:langhelp_toggle_narrowing, :interactive=>true,
|
828
|
+
:docstring=>"Toggle narrowing to the current section.") do
|
829
|
+
if narrowing?
|
830
|
+
widen
|
831
|
+
else
|
832
|
+
langhelp_narrow_to_section
|
833
|
+
end
|
834
|
+
end
|
835
|
+
|
836
|
+
el4r_lisp_eval %q(
|
837
|
+
(defmacro lh-center (&rest body)
|
838
|
+
`(progn
|
839
|
+
,@body
|
840
|
+
(save-selected-window
|
841
|
+
(other-window 1)
|
842
|
+
(recenter '(1)))))) #'`
|
843
|
+
|
844
|
+
defun(:langhelp_test_definition, :interactive=>"sLanghelp doc definition: ",
|
845
|
+
:docstring=>"Issue `mklanghelp --eval' for input") do |docdef|
|
846
|
+
docdef = docdef.sub(/,\s*$/,'')
|
847
|
+
shell_command "mklanghelp --eval='#{docdef}'"
|
848
|
+
end
|
849
|
+
|
850
|
+
defun(:langhelp_test_definition_this_line, :interactive=>true,
|
851
|
+
:docstring=>"Issue `mklanghelp --eval' for this line") do
|
852
|
+
langhelp_test_definition(buffer_substring(point_at_bol, point_at_eol))
|
853
|
+
end
|
854
|
+
|
855
|
+
end #/LangHelp::LangHelp
|
856
|
+
|
857
|
+
# (lh-sh "(echo a;echo b)" "b")
|
858
|
+
# (el4r-ruby-eval "LangHelp.run")
|
859
|
+
|
860
|
+
end #/LangHelp
|
861
|
+
|
862
|
+
# Local Variables:
|
863
|
+
# modes: (el4r-mode emacs-lisp-mode)
|
864
|
+
# End:
|