Re: How to implement custom compile/run commands?

From: Robert <ro....at.web.de>
Date: Wed, 12 May 2010 13:29:23 +0200

On Tue, May 11, 2010 at 11:22 PM, phayz <russelldicken....at.gmail.com> wrote:

> On May 11, 6:56 pm, Robert <ro....at.web.de> wrote:
> > On Tue, May 11, 2010 at 1:21 AM, phayz <russelldicken....at.gmail.com>
> wrote:
> > > On May 11, 8:20 am, phayz <russelldicken....at.gmail.com> wrote:
> > >> On May 11, 2:36 am, mitchell <mforal.n....at.gmail.com> wrote:
> >
> > >> > Hi Russell,
> >
> > >> > On May 10, 1:30 am, phayz <russelldicken....at.gmail.com> wrote:
> >
> > >> > > I have searched and browsed this group and Textadept's
> documentation
> > >> > > but I am still not sure how I implement language-specific
> compile/run
> > >> > > commands.
> >
> > >> > > I browsed textadept\modules\textadept\run.lua and in that file
> found
> > >> > > the text -
> > >> > > "-- Module for running/executing source files.
> > >> > > -- Typically, language-specific modules populate the
> > >> > > 'compile_command',
> > >> > > -- 'run_command', and 'error_detail' tables for a particular
> > >> > > language's file
> > >> > > -- extension."
> >
> > >> > > With that information I then browsed and opened the file textadept
> > >> > > \modules\cpp\commands.lua and in that file found the text -
> > >> > > "-- Commands for the cpp module.
> > >> > > module('_m.cpp.commands', package.seeall)"
> >
> > >> > > The lines immediately following this text configured the 'run' and
> > >> > > 'compile' commands for this file type.
> >
> > >> > > Although I don't fully understand the patterns used, I get the
> gist of
> > >> > > these files.
> >
> > >> > > If I want to implement, for example, hypertext-specific 'run' and
> > >> > > 'compile' commands, would I create a textadept\modules\hypertext
> > >> > > \commands.lua file and in it, detail the appropriate commands?
> >
> > >> > > If my understanding of how file type-specific 'run' and 'compile'
> > >> > > commands is incorrect, as usual I am open to constructive
> criticism.
> >
> > >> > -- modules/hypertext/commands.lua
> >
> > >> > local m_run = _m.textadept.run
> >
> > >> > m_run.compile_command.hypertext = "tidy %(filename)"
> > >> > m_run.run_command.hypertext = "firefox file://%(filename)"
> >
> > >> > Maybe I am misunderstanding your question.
> >
> > >> > Mitchell
> >
> > >> > > Regards,
> >
> > >> > > Russell Dickenson
> >
> > >> Mitchell,
> >
> > >> You understand my question perfectly! :) In reply to your answer, I
> > >> don't have a modules/hypertext/commands.lua module. Is this part of a
> > >> commit made after 2.2 beta 2 was released? I am currently running 2.2
> > >> beta 2 under Windows.
> >
> > >> Regards,
> >
> > >> Russell Dickenson
> >
> > > Mitchell,
> >
> > > Sorry, I realise I may have complicated things even more with my
> > > reply. In your reply are you providing an *example* of how I might
> > > implement custom 'run' and 'compile' commands, or are you pointing me
> > > to a file which should already exist in my instance of Textadept? In
> > > implementing an XML tags autocomplete module, also hypertext snippets,
> > > I have a "modules/hypertext/commands.lua" in my personal Textadept
> > > directory. I added the to this file the lines in your reply but
> > > selecting 'Run' and 'Compile' from Textadept's menu have no effect at
> > > all. I don't get any error messages etc, so I don't know where I might
> > > be going wrong. I will try to replace my hypertext commands.lua with
> > > only the lines that you provided and see if this works.
> >
> > > Regards,
> >
> > > Russell Dickenson
> >
> > Russell,
> > just to make sure, do you have a file modules/hypertext/init.lua ?
> > A file commands.lua would not get loaded automatically.
> > It should look something like this:
> >
> > -- The hypertext module.
> > -- It provides utilities for editing Hypertext.
> > module('_m.hypertext', package.seeall)
> >
> > if type(_G.snippets) == 'table' then
> > ---
> > -- @class table
> > -- @name snippets.hypertext
> > _G.snippets.hypertext = {}
> > end
> >
> > if type(_G.keys) == 'table' then
> > ---
> > -- @class table
> > -- @name keys.hypertext
> > _G.keys.hypertext = {}
> > end
> >
> > require 'hypertext.commands'
> > require 'hypertext.snippets'
> >
> > function set_buffer_properties()
> > end
> >
> > Assuming that you have a file hypertext/snippets.lua as well.
> > Alternatively you could
> > require 'hypertext.commands'
> > in your .textadept/init.lua but simply copying the design of the
> > existing modules is probably better.
> >
> > Robert
>
>
> Mitchell and Robert,
>
> Thanks for your help so far. I do have a personal hypertext/init.lua
> file, which is identical to the content you quoted above, Robert. In
> my personal hypertext/command.lua file I pasted the lines given by
> Mitchell, with the resulting file having the following content:
>
> START >>>>>>>>
> ---
> -- Commands for the hypertext module.
> module('_m.hypertext.commands', package.seeall)
>
> require 'common.xmlcomplete'
>
> local m_run = _m.textadept.run
>
> m_run.compile_command.hypertext = "tidy %(filename)"
> m_run.run_command.hypertext = "cmd.exe"
> -- m_run.run_command.hypertext = "C:\z\PortableApps\PortableApps
> \FirefoxPortable\FirefoxPortable.exe file://%(filename)"
>
> -- hypertext-specific key commands.
> local keys = _G.keys
> if type(keys) == 'table' then
> keys.hypertext = {
> al = {
> m = { textadept.io.open,
>
> textadept.iconv(_HOME..'/modules/hypertext/init.lua',
> 'UTF-8', _CHARSET) },
> },
> ['cs\n'] = {completeClosingTag},
> ['>'] = {completeClosingTagBracket},
> -- ['<'] = {autoTag},
> ['/'] = {singleTag},
> -- [' '] = {
> -- function ()
> -- local pos = buffer.current_pos
> -- buffer:clear_selections()
> -- buffer:set_sel(pos, pos)
> -- buffer:add_text(" ")
> -- end
> -- }
> }
> end
> END <<<<<<<<<<
>
> Textadept doesn't give any error messages on startup so I assume my
> hypertext/init.lua file's syntax is correct. However when I have a
> hypertext file loaded and select 'Tools > Run' or 'Tools > Compile'
> from the menu, nothing happens. To try and eliminate the commands
> themselves as an issue I tried a much simplified 'run' command, which
> was launch the Windows command prompt - cmd.exe. Again, nothing
> happened when I selected 'Tools > Run' from the menu.
>
> For reference the contents of my personal hypertext/init.lua are as
> follows:
>
> START >>>>>>>>>>>>
> ---
> -- The hypertext module.
> -- It provides utilities for editing hypertext code.
> module('_m.hypertext', package.seeall)
>
> if type(_G.snippets) == 'table' then
> ---
> -- Container for hypertext-specific snippets.
> -- @class table
> -- @name snippets.hypertext
> _G.snippets.hypertext = {}
> end
>
> if type(_G.keys) == 'table' then
> ---
> -- Container for hypertext-specific key commands.
> -- @class table
> -- @name keys.hypertext
> _G.keys.hypertext = {}
> end
>
> require 'hypertext.commands'
> require 'hypertext.snippets'
>
> function set_buffer_properties()
>
> end
> END <<<<<<<<<<<<<<
>
> In case it's of help, here is the content of my personal init.lua
> file:
>
> START >>>>>>>>>>>
> -- Core extension modules to load on startup.
> require 'ext/keys' -- provides key command support
> require 'ext/find' -- provides functionality for find/replace
> require 'ext/command_entry' -- provides tab-completion for the command
> entry
> require 'ext/mime_types' -- provides support for language detection
> based on
> -- the file; loads its language-specific
> module if
> -- it exists
>
> -- Generic modules to load on startup.
> require 'textadept'
>
> -- Core extension modules that must be loaded last.
> require 'ext/menu' -- provides the menu bar
> require 'ext/key_commands' -- key commands
>
> -- Personal modules (obtained from Textadept wiki etc)
> require 'bufferutils'
> END <<<<<<<<<<<<<
>
> Can anyone see where I might be going wrong?
>
> I also run Textadept under Linux at home, but I am doing all my
> diagnosis of this problem under Windows XP, as I have different
> versions on both PCs.
>
>
> Regards,
>
> Russell Dickenson
>
> It's a bug. The run function looks for file extensions. So either have
m_run.run_command.html = 'something...'
or change the run function in run.lua (most likely similar to the long-term
solution) to:

function run()
  if not buffer.filename then return end
  buffer:save()
  local action = run_command[buffer:get_lexer_language()] -- CHANGED
  if action then execute(type(action) == 'function' and action() or action)
end
end

Mitchell, is there a buffer attribute with the current lexer language? I
thought there was one, but I couldn't find it.

Robert

-- 
You received this message because you are subscribed to the Google Groups "textadept" group.
To post to this group, send email to textadept.at.googlegroups.com.
To unsubscribe from this group, send email to textadept+unsubscribe.at.googlegroups.com.
For more options, visit this group at http://groups.google.com/group/textadept?hl=en.
Received on Wed 12 May 2010 - 07:29:23 EDT

This archive was generated by hypermail 2.2.0 : Thu 08 Mar 2012 - 11:45:27 EST