Class: LangHelp::LangHelpInternal

Inherits:
ElApp
  • Object
show all
Defined in:
lib/el4r/emacsruby/langhelp.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(x) ⇒ LangHelpInternal

Returns a new instance of LangHelpInternal.



126
127
128
129
130
131
132
133
134
# File 'lib/el4r/emacsruby/langhelp.rb', line 126

def initialize(x)
  @mmode = x[:major_mode]
  @dir = x[:datadir]
  @efile = "#{@dir}/#{@mmode}.e"
  @header = "#{@dir}/#{@mmode}-header.e"
  @encoding = x[:encoding] || :euc_jp
  @buffer_ctime = 0
  @use_frame = x[:use_frame]
end

Instance Attribute Details

#bufObject (readonly)

Returns the value of attribute buf.



135
136
137
# File 'lib/el4r/emacsruby/langhelp.rb', line 135

def buf
  @buf
end

#dirObject (readonly)

Returns the value of attribute dir.



135
136
137
# File 'lib/el4r/emacsruby/langhelp.rb', line 135

def dir
  @dir
end

#efileObject (readonly)

Returns the value of attribute efile.



135
136
137
# File 'lib/el4r/emacsruby/langhelp.rb', line 135

def efile
  @efile
end

#headerObject (readonly)

Returns the value of attribute header.



135
136
137
# File 'lib/el4r/emacsruby/langhelp.rb', line 135

def header
  @header
end

#mmodeObject (readonly)

Returns the value of attribute mmode.



135
136
137
# File 'lib/el4r/emacsruby/langhelp.rb', line 135

def mmode
  @mmode
end

Instance Method Details

#create_bufferObject



137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
# File 'lib/el4r/emacsruby/langhelp.rb', line 137

def create_buffer
  @buffer_ctime = Time.now
  @buf = newbuf(:name => "*langhelp:#{mmode}*") do
    let(:coding_system_for_read, @encoding) do 
      if File.exist?(header)
        insert_file_contents header
        goto_char point_max
        insert "\n\n"
      end
      insert_file_contents efile
      goto_char 1
    end
 
    cd dir
    langhelp_menu_mode

    # I do not know why `hack_local_variables' in langhelp_menu_mode does not work well.
    hack_local_variables
    with(:save_excursion) { lh_imenu_create_index }
  end
  @buf

end

#header_is_newer_than_buffer(file = @header) ⇒ Object



161
162
163
# File 'lib/el4r/emacsruby/langhelp.rb', line 161

def header_is_newer_than_buffer(file=@header)
  File.mtime(file) > @buffer_ctime
end

#selbuf(buf) ⇒ Object



165
166
167
168
169
170
171
172
# File 'lib/el4r/emacsruby/langhelp.rb', line 165

def selbuf(buf)
  if @use_frame
    switch_to_buffer(buf)
    bury_buffer(buf)
  else
    pop_to_buffer(buf)
  end
end

#setup_bufferObject



174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
# File 'lib/el4r/emacsruby/langhelp.rb', line 174

def setup_buffer
  if File.exist?(efile)
    if @use_frame
      langhelp_select_frame
    else
      winconf_push
    end
    if buffer_live_p(@buf) and not header_is_newer_than_buffer
      selbuf @buf
    else
      selbuf create_buffer
    end
    yield(@buf)
  end
end