file-tool-setup - Define file-browser tools
file-tool-setup
file-tool-setup provides a dialog interface for declaring a set of actions to act on files shown in the file-browser(3) directory listing. Actions may be defined to interact with ZIP files for both creation and extraction, opening of PDF files with Adobe Acrobat, opening of Microsoft Word DOC files with Word or StarOffice etc. These options are shown in the file-browser pop-up menu under Tools.
The file tools may be configured from user-setup(3) in the Miscellaneous tab or invoked directly from the command line using file-tool-setup, when invoked then the File Tool Setup dialog is displayed. The dialog allows commands to be be matched against certain file types that are determined using a regular expression, if a filename matches the pattern then a command line or MicroEmacs command may be invoked to process the file(s). The command line includes variables which are filled in by MicroEmacs. The information is stored in the registry user.erf and is retained across sessions.
The file-tool-setup presents a list of tools, there is no limit to the number of tools which can be defined or to the number of tools that may map to a specific file type. The dialog has the following fields:
Name
File Mask
Command
%f - Filename
%b - Base Filename
%e - File Extension
%p, %P - File pathname
%i[h|prompt|default] .. %n - User Input
h specifies the type of data to be entered including the history and semantics allowed. h may have the following values:
0 For a general string input using the general history.
1 For an absolute file name, with completion and history.
2 For a MicroEmacs buffer name, with completion and history.
3 For a MicroEmacs command name, with completion and history.
4 For a file name, with completion and history.
5 For a search string, with history.
6 For a MicroEmacs mode name, with completion and history.
7 For a MicroEmacs variable name, with completion and history.
8 For a general string using no history.
9 For a user supplied completion list (com-list).
a For a user supplied completion list (buffer-name).
prompt is the prompt string presented on the command line.
default is the default value that should be used. The % characters may be used and will be replaced with information from the filename e.g. %b would be replaced with the base file name.
As an example of the user input, consider the following command line which is used to unzip a .zip file:
unzip "%f" -d %i[4|Unzip sub-dir|%b]
Given an input file of /home/user/foo.zip then the command line unzip "/home/user/foo.zip" -d foo is generated, given that the user accepted the defualt command line prompt of "foo" for the prompt "Unzip sub-dir"
Where the user input is required in multiple parts of the command line then the %1 syntax may be used. The following example may be used to create a .zip archive from one or more selections in the file list.
rm -f "%i[4|Zip file name|%b].zip"; zip -r %1.zip%*[ "%f"]
In this instance the user is prompted for the Zip file name and it is used twice in the command line, the default name is the base file name of the first file. Consider two files have been selected foo.txt and bar.txt where foo.txt is first. The generated command line is:
rm -f "foo.zip"; zip -r foo.zip "foo.txt" "bar.txt"
Note how the basename has been used as the default for the zip file name to create and this has been used in two places in the command line, once to delete the old archive if it already exists and once to form the new archive.
%*[argument] - Multiple file command line
The square bracket construct contains the expansion for each file specified in the file-browser, this will typically include the %f construct. For each argument then the brackets are expanded and concatenated together to form a command line, as such the bracket construct usually starts with a space character as this separates the files.
As an example then zip file construction will take multiple files on the command line to add to the archive:
rm -f "%i[4|Zip file name|%b].zip"; zip -r %1.zip%*[ "%f"]
%"...%" - Quote text
unzip %f
is used for the file "Test Files.zip" the command-line becomes 'unzip Test Files.zip' which will not work correctly, conversely using "%f" will not work for files with quotes (e.g. '2"bolt.def'). However, if
unzip %"%f%"
is used MicroEmacs works out the best way to quote the file name for it to be properly processed.
*MicroEmacs-Command - Internal command
*find-zfile "%f"
For each file then find-zfile is invoked to read the zip archive.
Default Open
Hide Window
Up/Down
Add
Modify
Delete
Close
Example tool definitions:
Word processor
Image Viewer
Postscript Viewer
Acrobat Viewer
Unzip a zip Archive in current directory
Unzip a zip Archive in a sub-directory
Create a zip archive
Add to a zip archive
View archive file
Convert files to UNIX
Microsoft Windows - default action
Microsoft Windows - Explorer
(c) Copyright JASSPA 2009
Last Modified: 2009/08/29
Generated On: 2009/10/12