Class: GonzuiEmacs

Inherits:
ElApp
  • Object
show all
Includes:
LangHelp::DisplayResult
Defined in:
lib/el4r/emacsruby/gonzui-emacs.rb

Overview

This program is free software; you can redistribute it and/or modify

it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
  This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.
  You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

Instance Method Summary collapse

Constructor Details

#initialize(x = {}) ⇒ GonzuiEmacs

Returns a new instance of GonzuiEmacs.



18
19
20
21
22
23
# File 'lib/el4r/emacsruby/gonzui-emacs.rb', line 18

def initialize(x={})
  defun_gonzui
  defun_lh_gonzui
  defun_gonzui_sentinel
  defun_gonzui_filter
end

Instance Method Details

#_shell_command_setup(buf) ⇒ Object



63
64
65
66
67
68
69
70
71
72
# File 'lib/el4r/emacsruby/gonzui-emacs.rb', line 63

def _shell_command_setup(buf)
  let(:coding_system_for_read, :euc_jp) {
    set_buffer(get_buffer_create(buf))
    erase_buffer
    buffer_disable_undo
    yield
    switch_to_buffer buf
    goto_char 1
  }
end

#defun_gonzuiObject



89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# File 'lib/el4r/emacsruby/gonzui-emacs.rb', line 89

def defun_gonzui
  defun(:display_gonzui_result) do |q|
    winconf_push
    buf = "*gonzui-result:#{q}*"
    do_gonzui_search_command "ruby -S gonzui-search-emacs.rb #{q.inspect}", buf
    # The gonzui process is running at this time.
    langhelp_menu_mode
    hl_line_mode 0 if fboundp :hl_line_mode
    elvar.header_line_format = nil
    make_local_variable :ee_anchor_format
    elvar.ee_anchor_format = "== %s =="
    # TODO: customizable
    elvar.tab_width = 78
  end

  defun(:gonzui, :interactive=>"sGonzui: ") do |q|
    display_gonzui_result q
    delete_other_windows
  end

  defun(:gonzui_defun_pkg) do
    `gonzui-db --list`.each do |pkg|
      pkg.chomp!
      defun("gonzui-pkg-#{pkg}", :interactive=>"sGonzui -P #{pkg}: ") do |q|
        gonzui "-P #{pkg} #{q}"
      end
    end
  end

  defun(:gonzui_defun_type) do
    `ruby -rlangscan -e 'puts LangScan::Type::TypeRegistry.keys'`.each do |type|
      type.chomp!
      defun("gonzui-type-#{type}", :interactive=>"sGonzui -t #{type}: ") do |q|
        gonzui "-t #{type} #{q}"
      end
    end
  end
end

#defun_gonzui_filterObject



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/el4r/emacsruby/gonzui-emacs.rb', line 46

def defun_gonzui_filter
  # (find-efunction 'ansi-color-apply-on-region)
  # (find-node "(elisp-ja)Filter Functions" "ordinary-insertion-filter")
  el_require :ansi_color
  el4r_lisp_eval %(
    (defun gonzui-filter (proc string)
      (with-current-buffer (process-buffer proc)
        (let ((moving (= (point) (process-mark proc))))
          (save-excursion
            (goto-char (process-mark proc))
            (insert string)
            (ansi-color-apply-on-region (process-mark proc) (point))
            (set-marker (process-mark proc) (point)))
          (if moving (goto-char (process-mark proc)))))))
  byte_compile :gonzui_filter
end

#defun_gonzui_sentinelObject



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/el4r/emacsruby/gonzui-emacs.rb', line 25

def defun_gonzui_sentinel
  # (find-node "(elisp-ja)Sentinels")
  defun(:gonzui_sentinel) do |process, process_is|
    if process_is == "finished\n"
      buf = process_buffer(process)
      set_buffer buf
      with(:save_excursion) {
        goto_char point_max
        re_search_backward "^== Package Index =="
        index_block = buffer_substring(point, point_max)
        delete_region point, point_max
        goto_char 1
        insert index_block
        hl_line_mode 1 if fboundp :hl_line_mode
      }
        
      funcall :message, "gonzui finished"
    end
  end
end

#defun_lh_gonzuiObject



129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
# File 'lib/el4r/emacsruby/gonzui-emacs.rb', line 129

def defun_lh_gonzui
  defun(:lh_gonzui, :interactive=>true) do |line, path|
    display_result(:line=>line, :centering=>true) do
      # TODO: real path
      buf = "*gonzui:#{path}*"
      if get_buffer(buf)
        switch_to_buffer buf
      else
        do_shell_command "ruby -S gonzui-db-emacs.rb -r #{path}", buf
        let(:buffer_file_name, "/"+path){ set_auto_mode } rescue nil # ignore errors
        view_mode 1
      end
    end
  end

  defun(:lh_gonzui_pkg, :interactive=>true) do |pkg|
    winconf_push
    search_anchor "Path Index"
    re_search_forward /^#{Regexp.quote(pkg)}/
    beginning_of_line
  end

end

#do_gonzui_search_command(cmd, buf) ⇒ Object



74
75
76
77
78
79
80
81
# File 'lib/el4r/emacsruby/gonzui-emacs.rb', line 74

def do_gonzui_search_command(cmd, buf)
  _shell_command_setup(buf) {
    with(:save_excursion){ insert "\n" } # To avoid scrolling
    process = start_process "gonzui", buf, elvar.shell_file_name, elvar.shell_command_switch, cmd
    set_process_sentinel process, :gonzui_sentinel
    set_process_filter process, :gonzui_filter
  }
end

#do_shell_command(cmd, buf) ⇒ Object



83
84
85
86
87
# File 'lib/el4r/emacsruby/gonzui-emacs.rb', line 83

def do_shell_command(cmd, buf)
  _shell_command_setup(buf) {
    shell_command cmd, buf
  }
end