| 1 |
% |
| 2 |
% \iffalse |
| 3 |
%<*driver> |
| 4 |
\documentclass[a4paper]{tclldoc} |
| 5 |
|
| 6 |
\newcommand{\eemenu}{\textsf{EE} menu} |
| 7 |
\DeclareRobustCommand\Alpha{\textit{Alpha}} |
| 8 |
\DeclareRobustCommand\AlphaEight{\textit{Alpha\,8}} |
| 9 |
\DeclareRobustCommand\AlphaTk{\textit{Alphatk}} |
| 10 |
\DeclareRobustCommand\AlphaTcl{\textit{Alpha\Tcllogo}} |
| 11 |
\DeclareRobustCommand\TclAE{\Tcllogo\AE} |
| 12 |
\DeclareRobustCommand\package[1]{\textsf{#1}} |
| 13 |
|
| 14 |
\providecommand{\href}[2]{#2} |
| 15 |
|
| 16 |
\usepackage{xdoc2} |
| 17 |
\newenvironment{details}[1]{% |
| 18 |
\description |
| 19 |
\def\commandmethod{#1}% |
| 20 |
}{\enddescription} |
| 21 |
\makeatletter |
| 22 |
\newcommand{\detailitem}{% |
| 23 |
\XD@grab@arguments{\@detailitem}{\XD@grab@harmless\relax}% |
| 24 |
} |
| 25 |
\def\@detailitem#1{% |
| 26 |
\item[\texttt{#1}% |
| 27 |
\IndexEntry{\LevelSame{\commandmethod\ method}% |
| 28 |
\LevelSorted{#1}{\texttt{#1} detail}% |
| 29 |
}{main}{\TheXDIndexNumber}% |
| 30 |
]% |
| 31 |
} |
| 32 |
\makeatother |
| 33 |
|
| 34 |
% \addtolength{\marginparwidth}{0.7cm} |
| 35 |
|
| 36 |
\CodelineIndex |
| 37 |
\setcounter{IndexColumns}{2} |
| 38 |
|
| 39 |
\begin{document} |
| 40 |
\DocInput{eemenu.dtx} |
| 41 |
\PrintIndex |
| 42 |
\end{document} |
| 43 |
%</driver> |
| 44 |
% \fi |
| 45 |
% |
| 46 |
% \title{The \eemenu} |
| 47 |
% \author{Lars Hellstr\"om} |
| 48 |
% \date{17 July 2003} |
| 49 |
% \maketitle |
| 50 |
% |
| 51 |
% |
| 52 |
% \begin{abstract} |
| 53 |
% The \eemenu\ package for the \Alpha\ family of text editors provides |
| 54 |
% commands for sending small pieces of code from a source file window |
| 55 |
% to various interpreters. It can handle multiple languages and |
| 56 |
% multiple source file formats. |
| 57 |
% \end{abstract} |
| 58 |
% |
| 59 |
% \tableofcontents |
| 60 |
% |
| 61 |
% |
| 62 |
% \section{Introduction} |
| 63 |
% |
| 64 |
% When writing code for an interpreted language, it is a great |
| 65 |
% convenience to be able to test arbitrary pieces of code by sending |
| 66 |
% them to a relevant interpreter and examining the results. Many of |
| 67 |
% \Alpha's modes provide such functionality, but not always with the |
| 68 |
% full generality one would need. Furthermore these features are usually |
| 69 |
% tied to the specific mode and thus become much less convenient if code |
| 70 |
% in several different languages are mixed in the same file. The |
| 71 |
% \eemenu\ provides a general mechanism for constructing new commands |
| 72 |
% of this kind, thereby making it possible to better tailor them for the |
| 73 |
% case at hand. |
| 74 |
% |
| 75 |
% |
| 76 |
% \subsection{Using an \eemenu\ command} |
| 77 |
% |
| 78 |
% The basic usage is straightforward: you select a piece of text and |
| 79 |
% invoke one of the \eemenu\ commands. This will \emph{extract} |
| 80 |
% the part of that selection which is code and send it to the relevant |
| 81 |
% interpreter, where it will be \emph{evaluated}. (Indeed, the \textsf{EE} |
| 82 |
% in \eemenu\ is for ``extract and evaluate''.) You will also get |
| 83 |
% a \emph{report} (by default a message on the status line) about the |
| 84 |
% result of the command. This is all quite similar to how the |
| 85 |
% \textsf{Evaluate} command in the \Tcllogo\ menu works, but it is much |
| 86 |
% more general. |
| 87 |
% |
| 88 |
% Two very natural questions at this point are of course ``How does it |
| 89 |
% know what part of the selection is `code'?'' and ``How does it know |
| 90 |
% which the `relevant interpreter' is?''. The answer to both these |
| 91 |
% questions is that this information is built into the particular command |
| 92 |
% you invoke. Just as the standard \textsf{Evaluate} command has its |
| 93 |
% definition of what `code' is (the entire selection is code) and which |
| 94 |
% the `relevant interpreter' is (\Alpha's internal \Tcllogo\ |
| 95 |
% interpreter), each \eemenu\ command has built-in definitions of |
| 96 |
% these things. The difference is that with \textsf{Evaluate} you would |
| 97 |
% have to do some programming to change these things, whereas with the |
| 98 |
% \eemenu\ commands you don't, since there is a multitude of ways in |
| 99 |
% which each part of the exatract-and-evaluate process can be configured. |
| 100 |
% |
| 101 |
% To begin with, each \eemenu\ command consists of four pieces which |
| 102 |
% are quite independent of each other. When the \emph{extract} piece is |
| 103 |
% called it looks at the selection and returns the next line of code in |
| 104 |
% it, or says that there are no more code lines that can be extracted. |
| 105 |
% What happens to the extracted lines of code is of no concern to the |
| 106 |
% extractor. The \emph{evaluate} piece takes a list of lines and sends |
| 107 |
% them to an interpreter (internal or external). It also compiles a |
| 108 |
% sort of report on the result of the evaluation, based on the reply |
| 109 |
% (if there was any) that it recieves from the interpreter. This is |
| 110 |
% then given to the \emph{reporter}, which displays the report (or more |
| 111 |
% often, for brevity, the central part of the report) to the user. The |
| 112 |
% fourth piece is called the \emph{completeness test} and determines |
| 113 |
% whether a list of code lines constitute a unit that can be evaluated. |
| 114 |
% |
| 115 |
% The way it goes is that lines are extracted until the completeness |
| 116 |
% test says OK, then the lines are sent for evaluation and the report on |
| 117 |
% evaluation is sent to the reporter, after which the whole thing starts |
| 118 |
% again and lines are extracted until the form a new complete unit, |
| 119 |
% which is then evaluated, and so on. The \eemenu\ command doesn't stop |
| 120 |
% until all code lines in the selection have been extracted or evaluation |
| 121 |
% reports an error. |
| 122 |
% If there is an error in evaluation then the report will say so, and |
| 123 |
% futhermore the cursor will be moved to the beginning of the first |
| 124 |
% line in the code unit that failed to evaluate correctly. Furthermore |
| 125 |
% the pin will be moved to the end of the selection, so that a simple |
| 126 |
% \textsf{Hilite} will reselect the part of the original selection that |
| 127 |
% still has not been successfully evaluated. If there wasn't any |
| 128 |
% selection to start with then the extractor behaves as if the entire |
| 129 |
% file was selected. |
| 130 |
% |
| 131 |
% |
| 132 |
% \subsection{Editing and invoking \eemenu\ commands} |
| 133 |
% |
| 134 |
% Each of the four pieces of what a command does are handled by a |
| 135 |
% \emph{method}. There are extraction methods, completeness test |
| 136 |
% methods, evaluation methods, and report methods, all of which can be |
| 137 |
% combined arbitrarily to make up a new \eemenu\ command. This is done |
| 138 |
% in the \textsf{Edit Commands} dialog, which is brought up by |
| 139 |
% choosing that item in the \textsf{EE} menu. |
| 140 |
% |
| 141 |
% The \textsf{Edit Commands} dialog has one page for each \eemenu\ |
| 142 |
% command that is defined. At the bottom of the dialog there is a row |
| 143 |
% of four buttons \textsf{New}, \textsf{Duplicate}, \textsf{Rename}, and |
| 144 |
% \textsf{Delete} which add, remove, or rename \eemenu\ commands. Above |
| 145 |
% those are four pop-up menus, in which one chooses which four methods |
| 146 |
% the command should consist of. Above these are four other items which |
| 147 |
% control how the command is invoked. |
| 148 |
% |
| 149 |
% There are two ways of invoking an \eemenu\ command. One possibility |
| 150 |
% is to choose it directly in the \textsf{EE} menu, although it is not |
| 151 |
% necessarily the case that all commands are available there. Whether a |
| 152 |
% command is available is controlled through the \textsf{Put in menu} |
| 153 |
% item on the \textsf{Edit Commands} dialog page of that command. The |
| 154 |
% other possibility of invoking a command is through a key binding, and |
| 155 |
% that is controlled through the three remaining items \textsf{Active}, |
| 156 |
% \textsf{Command keybinding}, and \textsf{Binding mode} in the |
| 157 |
% \textsf{Edit Commands} dialog. The \textsf{Command keybinding} item |
| 158 |
% controls which key binding one should use for a command. The |
| 159 |
% \textsf{Binding mode} item is used to specify a mode for this |
| 160 |
% binding; a binding without mode will be global. Finally, a command is |
| 161 |
% said to be \emph{active} if there is a key binding to it. The |
| 162 |
% \textsf{Active} item controls whether the command should be active by |
| 163 |
% default (at startup). |
| 164 |
% |
| 165 |
% For temporary activation and deactivation of commands, one should |
| 166 |
% instead use the \textsf{Active Commands} submenu of the \textsf{EE} |
| 167 |
% menu. This submenu lists all \eemenu\ commands. Those that are |
| 168 |
% currently active have a check mark next to them, and selecting an item |
| 169 |
% in this menu toggles activation state of that command. If two commands |
| 170 |
% have the same binding then activating one will deactivate the other. |
| 171 |
% |
| 172 |
% Besides the items mentioned above, the \textsf{Edit Commands} dialog |
| 173 |
% also has a \textsf{Details} button in the lower left corner. This |
| 174 |
% button is very important, since it brings up a subdialog that shows |
| 175 |
% all the method-specific settings. The methods and their details are |
| 176 |
% described below, but it should be observed here that it is to a large |
| 177 |
% extent these detail settings that decide, amogst other things, what |
| 178 |
% text should count as extractable code and which interpreter should |
| 179 |
% evaluate the code. To get back from the details subdialog to the main |
| 180 |
% \textsf{Edit Commands} dialog, one presses the \textsf{Back} button. |
| 181 |
% The details subdialog is logically a part (which is normally hidden) |
| 182 |
% of the main \textsf{Edit Commands} dialog. Changes to items in the |
| 183 |
% dialog, whether those appear in the main dialog or in the subdialog, |
| 184 |
% are kept if one presses \textsf{OK} in the main dialog and forgotten |
| 185 |
% if one presses the \textsf{Cancel} button. |
| 186 |
% |
| 187 |
% |
| 188 |
% \subsection{Extraction methods and their details} |
| 189 |
% |
| 190 |
% The default extraction method is the \textsf{Raw} method. It |
| 191 |
% considers the entire selection to be extractable code and has no |
| 192 |
% detail settings. |
| 193 |
% |
| 194 |
% The \textsf{Regexp} extraction method uses line-oriented regular |
| 195 |
% expressions to decide what is extractable code. This extraction |
| 196 |
% process works in two steps. First the lines in the selection are |
| 197 |
% tested against a filter, and those lines that passes are considered to |
| 198 |
% contain code. The filter works in one of three modes: \texttt{off} |
| 199 |
% (all lines pass), \texttt{grep} (only those lines that match a |
| 200 |
% specific regular expression passes), and \texttt{anti-grep} (only |
| 201 |
% those lines that \emph{don't} match a specific regular expression |
| 202 |
% passes). The filter mode and the regular expression used in the |
| 203 |
% filter are the two detail settings that affect the filter. |
| 204 |
% The second step in \textsf{Regexp} extraction is to feed each line |
| 205 |
% that passes the filter through |regsub|. This can be used to remove |
| 206 |
% from the lines some piece of text that is markup rather than part of |
| 207 |
% the code. Both the search and the replace regular expressions in this |
| 208 |
% step are detail settings of the \textsf{Regexp} extraction method. |
| 209 |
% |
| 210 |
% The \textsf{Docstrip} extraction method, finally, emulates what the |
| 211 |
% \textsf{docstrip} program\footnote{\textsf{docstrip} is part of the |
| 212 |
% standard \LaTeX\ distribution.} would do with the selection. It |
| 213 |
% recognises all kinds of guards and processes them correctly, but it |
| 214 |
% does not attempt to evaluate the guard expressions---instead it will |
| 215 |
% ask the user whether modules guarded by a given expression should be |
| 216 |
% included whenever it needs to know this. The values assigned to the |
| 217 |
% guard expressions will be forgotten each time the entire selection |
| 218 |
% is evaluated without error. Unlike \textsf{docstrip} the program, |
| 219 |
% \textsf{Docstrip} the extraction method will not include lines |
| 220 |
% beginning with |%%| in what is extracted, since those anyway only |
| 221 |
% contains comments. |
| 222 |
% |
| 223 |
% Besides the filtering that \textsf{docstrip} the program would do, |
| 224 |
% \textsf{Docstrip} the extraction method has two extra filtering |
| 225 |
% mechanisms that are designed mainly to prevent user errors. The first |
| 226 |
% is that extraction will only take place if the file name matches one |
| 227 |
% listed in the \textsf{File patterns} detail. The default pattern is |
| 228 |
% \texttt{*.dtx} which is usually what one wants, but changing it to |
| 229 |
% \texttt{*} will let anything through. The second mechanism, which is |
| 230 |
% off by default, sees to that code lines will only be considered for |
| 231 |
% extraction if they appear to be in an environment for code lines |
| 232 |
% (such as \texttt{macrocode}). This is useful if you in places tend to |
| 233 |
% leave a few lines of documentation not commented out during |
| 234 |
% development. To activate this mechanism, check the \textsf{Filter by |
| 235 |
% environments} detail. The \textsf{Source environments} detail is the |
| 236 |
% list of environments that are OK to extract from. |
| 237 |
% |
| 238 |
% As an example of how this works, consider a file that looks as |
| 239 |
% follows: |
| 240 |
% \DontCheckModules\iffalse |
| 241 |
%<*example> |
| 242 |
%<<EXAMPLE |
| 243 |
% \fi\begin{macrocode} |
| 244 |
% Text text text text text |
| 245 |
% \begin{tcl} |
| 246 |
set a A |
| 247 |
%<*andB> |
| 248 |
append a B |
| 249 |
%</andB> |
| 250 |
append a C |
| 251 |
%<*andD> |
| 252 |
append a D |
| 253 |
%</andB> |
| 254 |
expr $a |
| 255 |
string length $a |
| 256 |
% \end{tcl} |
| 257 |
% text text text. |
| 258 |
% \end{macrocode}\iffalse |
| 259 |
%EXAMPLE |
| 260 |
%</example> |
| 261 |
% \fi \CheckModules |
| 262 |
% If lines 1--7 above are selected and the \textsf{dtx -\textgreater\ |
| 263 |
% internal Tcl} command is invoked (the \eemenu\ by default binds this |
| 264 |
% to \textsf{Cmd--L}), then three messages will flash by on the |
| 265 |
% status line, the last (and therefore the lasting) of which is the |
| 266 |
% message \texttt{Tcl eval OK: ABC}. If using instead a command that |
| 267 |
% uses the \textsf{Log Window} report method, then in addition to this |
| 268 |
% one would have the following lines added to the log window: |
| 269 |
% \begin{trivlist}\item\small |
| 270 |
% |% set a A|\\ |
| 271 |
% |A|\\[\smallskipamount] |
| 272 |
% |% append a B|\\ |
| 273 |
% |AB|\\[\smallskipamount] |
| 274 |
% |% append a C|\\ |
| 275 |
% |ABC| |
| 276 |
% \end{trivlist} |
| 277 |
% The |%| lines show the commands that were evaluated and the |
| 278 |
% lines after these contain the respective results of these commands. |
| 279 |
% Before the |append a B| command is evaluated, \Alpha\ will stop and |
| 280 |
% ask |
| 281 |
% \begin{quote} |
| 282 |
% \textsf{Should \textless andB\textgreater\ modules be included?} |
| 283 |
% \end{quote} |
| 284 |
% In the case above the answer given was `Yes'; if it had been `No' then |
| 285 |
% the |append a B| command would neither be logged nor evaluated, and |
| 286 |
% the result of the |append a C| command would have been |AC|. |
| 287 |
% |
| 288 |
% If one continues by selecting lines 9--12 and invokes the same |
| 289 |
% command again then the status line will settle for the message |
| 290 |
% ``\texttt{Tcl\ eval\ error:\ syntax\ error\ in\ expression\ "ABCD"}'', |
| 291 |
% the insertion point will be moved to the beginning of line 11, and |
| 292 |
% the following information will be found in the log: |
| 293 |
% \begin{trivlist}\item\small |
| 294 |
% |% append a D|\\ |
| 295 |
% |ABCD|\\[\smallskipamount] |
| 296 |
% |% expr $a|\\ |
| 297 |
% |Error: syntax error in expression "ABCD"|\\ |
| 298 |
% |Error info:|\\ |
| 299 |
% |syntax error in expression "ABCD"|\\ |
| 300 |
% | while executing|\\ |
| 301 |
% |"expr $a"| |
| 302 |
% \end{trivlist} |
| 303 |
% If then line 11 is changed to |expr {$a}|, lines 11--12 are again |
| 304 |
% selected (e.g. using \textsf{Mark Hilite}), and the command is invoked |
| 305 |
% then logged material will be: |
| 306 |
% \begin{trivlist}\item\small |
| 307 |
% |% expr {$a}|\\ |
| 308 |
% |ABCD|\\[\smallskipamount] |
| 309 |
% |% string length $a|\\ |
| 310 |
% |4| |
| 311 |
% \end{trivlist} |
| 312 |
% |
| 313 |
% Finally, if lines 3--12 are selected and the command is invoked then |
| 314 |
% the user will be asked the following questions: |
| 315 |
% \begin{itemize} |
| 316 |
% \item \textsf{Should \textless andB\textgreater\ modules be included?} |
| 317 |
% (Possible answers are `Yes' and `No'.) |
| 318 |
% \item \textsf{Should \textless andD\textgreater\ modules be included?} |
| 319 |
% (Possible answers are `Yes' and `No'.) |
| 320 |
% \item \textsf{Module nesting error: \textless*andD\textgreater\ |
| 321 |
% module ended by \textless/andB\textgreater. For which |
| 322 |
% guards should the positions be pushed?} |
| 323 |
% (Possible answers are `None', `Start', `End', and `Both'.) |
| 324 |
% \end{itemize} |
| 325 |
% In the last case, the extraction method has noticed that the guard |
| 326 |
% expressions that began (\textsf{andD}) and ended (\textsf{andB}) a |
| 327 |
% module are not equal (which is an error). Answering `Both' here will |
| 328 |
% push the positions of (the beginning of) both guard lines (8 and 10) onto |
| 329 |
% the bookmark stack so that they can easily be jumped to and corrected |
| 330 |
% later. After this, the \eemenu\ command will continue as if nothing had |
| 331 |
% happened. |
| 332 |
% |
| 333 |
% |
| 334 |
% \subsection{Completeness tests} |
| 335 |
% |
| 336 |
% The three completeness tests that come with \eemenu\ are |
| 337 |
% \textsf{\Tcllogo\ Info Complete}, \textsf{Entire Selection}, and |
| 338 |
% \textsf{Every Line}. The first of these uses the |info complete| |
| 339 |
% command in \Alpha's built-in \Tcllogo\ interpreter test whether the |
| 340 |
% list of lines extracted so far constitute a complete \Tcllogo\ |
| 341 |
% script. \textsf{Entire Selection} and \textsf{Every Line} don't look |
| 342 |
% at the extracted lines at all however; instead the \textsf{Entire |
| 343 |
% Selection} test waits until the entire selection has been extracted |
| 344 |
% before it says it does constitute a complete unit, whereas |
| 345 |
% \textsf{Every Line} thinks every line is a complete unit. None of |
| 346 |
% these methods have any details. |
| 347 |
% |
| 348 |
% |
| 349 |
% \subsection{Evaluation methods} |
| 350 |
% |
| 351 |
% The list of available evaluation methods depends very much on the |
| 352 |
% current platform. The basic \eemenu\ package contains code for four |
| 353 |
% methods named \textsf{Internal Tcl}, \textsf{Do Script AE}, \textsf{Tk |
| 354 |
% Send}, and \textsf{Windoze DDE}, but only those for which the |
| 355 |
% underlying command can be found in the interpreter are actually |
| 356 |
% defined. The effect is usually that only two methods are available: |
| 357 |
% the \textsf{Internal Tcl} method and one method which depends on the |
| 358 |
% platform. |
| 359 |
% |
| 360 |
% The \textsf{Internal Tcl} method joins the lines of code with |
| 361 |
% linefeeds and passes the resulting string to \Alpha's internal |
| 362 |
% \Tcllogo\ interpreter for evaluation (at the global level). Errors |
| 363 |
% are caught and reported with a complete |errorInfo|. There are no |
| 364 |
% details for this method. |
| 365 |
% |
| 366 |
% The \textsf{Do Script AE} method sends a \texttt{dosc} AppleEvent with |
| 367 |
% the code to evaluate; hence it is only available on Mac~OS. The target |
| 368 |
% application for this event is one of the detail settings. The `Wait |
| 369 |
% for reply' detail setting controls whether the AppleEvent requests a |
| 370 |
% reply (not all target applications will provide one). If no reply is |
| 371 |
% requested then the report will only tell how many lines were sent. |
| 372 |
% If a reply is requested then that reply will be the report. Finally, |
| 373 |
% there are three detail settings that control how the list of lines |
| 374 |
% are converted to the string put in the \texttt{dosc} AppleEvent. The |
| 375 |
% lines can be joined using either of the following four strings: line |
| 376 |
% feed, carriage return, carriage return plus line feed, or just a |
| 377 |
% single space. It is also possible to specify a prefix and a suffix, |
| 378 |
% which are strings put before and after the extracted code that should |
| 379 |
% be evaluated. |
| 380 |
% |
| 381 |
% The \textsf{Tk Send} method uses the Tk |send| command to communicate |
| 382 |
% with the target interpreter; hence it is probably only useful with |
| 383 |
% \AlphaTk\ in an X-windows environment (typically on some Unix platform). |
| 384 |
% Most of the details work as for the \textsf{Do Script AE} method, but |
| 385 |
% there is a difference in how the target is identified. One detail |
| 386 |
% setting is the string used for identifying the target, but since the |
| 387 |
% names of targets for |send| are made unique on each server, there is |
| 388 |
% a chance that the intended target has not got the expected name. In |
| 389 |
% that case, a mechanism called `aliasing' will be invoked. It usually |
| 390 |
% displays a list of the available targets (which includes the option to |
| 391 |
% start a new Wish process) for the user to choose from, and the target |
| 392 |
% detail setting will then be considered to be an \emph{alias} for the |
| 393 |
% actual name of that target. If the alias behaviour is to ``Ask once'' |
| 394 |
% then this choice will be remembered as long as \Alpha\ is running, but |
| 395 |
% if it is to ``Ask each time'' then it will only work for this invocation |
| 396 |
% of the \eemenu\ command. The behaviour can also be to fail, in which |
| 397 |
% case the command stops as for an error without presenting the user with |
| 398 |
% a list of available targets. |
| 399 |
% |
| 400 |
% The \textsf{Windoze DDE} method uses Dynamic Data Exchange to communicate |
| 401 |
% with the target interpreter; hence it is probably only useful with |
| 402 |
% \AlphaTk\ on the Windows platform. Most of the details work as for the |
| 403 |
% \textsf{Tk Send} method, but there are a few extra details that have |
| 404 |
% to do with how the target is identified. The target is identified with |
| 405 |
% two details called \textsf{Service} and \textsf{Target}. For sending |
| 406 |
% commands to a \Tcllogo\ interpreter it seems like the \textsf{Service} |
| 407 |
% should be \texttt{TclEval} and the \textsf{Target} is assigned as the |
| 408 |
% \textsf{Target} for the \textsf{Tk Send} method, but the \Tcllogo\ |
| 409 |
% manual seems to suggest that the normal case is that the |
| 410 |
% \textsf{Service} is the name of an application and the |
| 411 |
% \textsf{Target} the name of a document open in that application (I |
| 412 |
% haven't had any chance to try it out in practice). Aliasing works as |
| 413 |
% for the \textsf{Tk Send} method, but since the target isn't |
| 414 |
% necessarily a \Tcllogo sh or Wish in this case, the actual command for |
| 415 |
% launching the new target must be configurable as well. This is the |
| 416 |
% purpose of the \textsf{Launch command} detail, whose value is a piece |
| 417 |
% of \Tcllogo\ code that \Alpha\ evaluates at the global level whenever |
| 418 |
% the user requests that a new target is launched. It is typically an |
| 419 |
% |exec| command. |
| 420 |
% |
| 421 |
% I am well aware that there are interpreters for which neither of these |
| 422 |
% methods may be appropriate. The method concept has however deliberately |
| 423 |
% been designed so that separate \AlphaTcl\ extensions can define new |
| 424 |
% methods that are just as easily available as the built-in ones. I |
| 425 |
% recommend that anyone who finds the available methods insufficient |
| 426 |
% tries to work out how one might otherwise communicate with the target |
| 427 |
% interpreter, so that the capabilities of \eemenu\ can be extended. One |
| 428 |
% particular possibility that should be explored is to (on Unix) hook up |
| 429 |
% interpreters as `slaves' of \Alpha\ (seizing control of |
| 430 |
% \texttt{stdin}, \texttt{stdout}, and \texttt{stderr}), so that the |
| 431 |
% target interpreter thinks it is getting text typed at an interactive |
| 432 |
% prompt. Since one would typically not want to start a new such `slave' |
| 433 |
% for each time an \eemenu\ command is invoked, it would probably be |
| 434 |
% necessary to add some functionality for managing slaves to the |
| 435 |
% \eemenu. |
| 436 |
% |
| 437 |
% |
| 438 |
% \subsection{Report methods} |
| 439 |
% |
| 440 |
% The default report method is \textsf{Status Line}, which shows the |
| 441 |
% most recent evaluation result on the status line. This is often |
| 442 |
% sufficient when all you're interested in is whether there was an |
| 443 |
% error or not. |
| 444 |
% |
| 445 |
% The \textsf{Log Window} report method creates a detailed log of the |
| 446 |
% commands evaluated and the results returned. This can be useful for |
| 447 |
% example when one is trying to debug a complex mathematical calculation |
| 448 |
% with several intermediate results. The first two details of this |
| 449 |
% method---\textsf{Window name} and \textsf{Window mode}---refer to the |
| 450 |
% window used to log the results. The logged text is inserted at the |
| 451 |
% end of this window. If no window with the specified name exists, then |
| 452 |
% a new one with mode \textsf{Window mode} and the shell flag set is |
| 453 |
% opened. The other details---\textsf{Prompt} and |
| 454 |
% \textsf{Antiprompt}---are text strings that are prepended to the |
| 455 |
% lines inserted into the log window. The \textsf{Prompt} is prepended |
| 456 |
% to extracted code lines, whereas the \textsf{Antiprompt} is prepended |
| 457 |
% to result lines. |
| 458 |
% |
| 459 |
% |
| 460 |
% \subsection{Writing new methods} |
| 461 |
% |
| 462 |
% A method consists of a couple of procedures which reside in a child |
| 463 |
% namespace of the \texttt{eemenu} namespace. Declaring a new method |
| 464 |
% simply amounts to writing these procedures and defining the detail |
| 465 |
% settings for the method. The general relation between method names and |
| 466 |
% namespace names is explained in Subsection~\ref{Ssec:Namespaces}. It |
| 467 |
% is suggested that one uses the \texttt{eemenu}\namespaceseparator |
| 468 |
% \texttt{define\_detail} command of Subsection~\ref{Ssec:CmdDialogs} |
| 469 |
% for defining detail settings. Different kinds of methods need to |
| 470 |
% provide different procedures for the main executive to call. The |
| 471 |
% interfaces used are described in the beginnings of |
| 472 |
% Sections~\ref{Sec:Extraction}--\ref{Sec:Report}. |
| 473 |
% |
| 474 |
% |
| 475 |
% |
| 476 |
% |
| 477 |
% \section{Main menu functionality} |
| 478 |
% |
| 479 |
% The rest of this paper describes the implementation of \eemenu\ and |
| 480 |
% its methods. The information here is useful mainly for those who want |
| 481 |
% to extend \eemenu\ by writing additional methods for it or otherwise |
| 482 |
% modify the code, but it could of course be of interest also for |
| 483 |
% advanced users. |
| 484 |
% |
| 485 |
% |
| 486 |
% \subsection{Initialization} |
| 487 |
% |
| 488 |
% \changes{v\,0.1}{2001/12/15}{Renamed package from \textsf{Eval~Menu} |
| 489 |
% to \textsf{EE~Menu}. (LH)} |
| 490 |
% \changes{v\,0.3}{2003/04/02}{Updated code for \AlphaTcl\,8. (LH)} |
| 491 |
% \changes{v\,0.3.1}{2003/07/19}{Added help. (LH)} |
| 492 |
% |
| 493 |
% \begin{tcl} |
| 494 |
%<*pkg> |
| 495 |
alpha::menu eeMenu 0.3.1 global "EE" { |
| 496 |
auto_load eemenu::main |
| 497 |
} { |
| 498 |
eemenu::init_bindings |
| 499 |
eemenu::build_menu |
| 500 |
} { |
| 501 |
eval eemenu::deactivate [array names eemenu::cmdA] |
| 502 |
} requirements { |
| 503 |
%<atcl7> alpha::package require AlphaTcl 7.5b1 |
| 504 |
%<!atcl7> alpha::package require AlphaTcl 8.0d1 |
| 505 |
} uninstall {this-file} help { |
| 506 |
The EE menu provides commands for sending small pieces of code |
| 507 |
from a source file window to various interpreters. It can handle |
| 508 |
multiple languages and multiple source file formats. |
| 509 |
|
| 510 |
The commands are built by combining four simple pieces called |
| 511 |
methods. The choice of methods and parameters for methods to |
| 512 |
use in a command is completely configurable through a dialog. |
| 513 |
It is also possible to write extensions that define additional |
| 514 |
methods and provide these through the same easy interface. |
| 515 |
|
| 516 |
See the file eemenu.dtx for the full documentation. |
| 517 |
} maintainer\ |
| 518 |
%<atcl7> [list "Lars Hellstr[text::Ascii 154 1]m" [email protected]] |
| 519 |
%<!atcl7> [list "Lars Hellstr\u00f6m" [email protected]] |
| 520 |
namespace eval eemenu {} |
| 521 |
% \end{tcl} |
| 522 |
% \setnamespace{eemenu} |
| 523 |
% |
| 524 |
% |
| 525 |
% \subsection{Methods and namespaces} |
| 526 |
% \label{Ssec:Namespaces} |
| 527 |
% |
| 528 |
% Each method for doing something is put in its own namespace, which |
| 529 |
% must be a child of the |eemenu| namespace. |
| 530 |
% |
| 531 |
% \begin{proc}{Prettify} |
| 532 |
% \begin{proc}{Unprettify} |
| 533 |
% In dialogs and preferences, method names are kept in ``prettified'' |
| 534 |
% form, similar to that used in most of \Alpha's menus. Since the |
| 535 |
% preference values must be restored to ``unpretty'' form before they |
| 536 |
% can be used, \eemenu\ has two procedures of its own that handle |
| 537 |
% these conversions, although the conversion is almost always the same |
| 538 |
% as the conversion that the standard |quote::Prettify| procedure |
| 539 |
% would make. The syntaxes are |
| 540 |
% \begin{quote} |
| 541 |
% |eemenu::Prettify| \word{unpretty string}\\ |
| 542 |
% |eemenu::Unprettify| \word{pretty string} |
| 543 |
% \end{quote} |
| 544 |
% \begin{tcl} |
| 545 |
proc eemenu::Prettify str { |
| 546 |
set a [string toupper [string index $str 0]] |
| 547 |
regsub -all {([^A-Z])([A-Z])} [string range $str 1 end] {\1 \2} b |
| 548 |
regsub -all {((La|Bib|Oz|CMac) )?Te X} $a$b {\2TeX } a |
| 549 |
return $a |
| 550 |
} |
| 551 |
proc eemenu::Unprettify str { |
| 552 |
regsub -all { } $str {} a |
| 553 |
return "[string tolower [string index $a 0]][string range $a 1 end]" |
| 554 |
} |
| 555 |
% \end{tcl} |
| 556 |
% For these procedures to be inverses of each other, unpretty strings |
| 557 |
% must begin with a lower case letter and not contain any spaces. |
| 558 |
% \end{proc}\end{proc} |
| 559 |
% |
| 560 |
% \begin{arrayvar}{extract}[method] |
| 561 |
% \begin{arrayvar}{complete}[method] |
| 562 |
% \begin{arrayvar}{evaluate}[method] |
| 563 |
% \begin{arrayvar}{report}[method] |
| 564 |
% A method declares itself by setting its entry in the |extract|, |
| 565 |
% |complete|, |evaluate|, or |report| respectively array. The |
| 566 |
% entries in these arrays are lists of dialog item names, more |
| 567 |
% precisely the names of those setting details that are relevant for |
| 568 |
% the method in question. The indices into these arrays are unpretty |
| 569 |
% method names. |
| 570 |
% \end{arrayvar}\end{arrayvar}\end{arrayvar}\end{arrayvar} |
| 571 |
% |
| 572 |
% Most method types employ a model with distinct ``begin'', ``iterate'', |
| 573 |
% and ``end'' procedures that the main executive calls. For each command |
| 574 |
% and method, the ``begin'' is called first once, then the ``iterate'' |
| 575 |
% may be called any number of times, and last the ``end'' is called once. |
| 576 |
% The details to use for the method are only provided in the call to |
| 577 |
% ``begin'' as that procedure is expected to store the relevant data |
| 578 |
% into variables private to the method (residing in its namespace). In |
| 579 |
% most cases, the actual code being evaluated is only handled by the |
| 580 |
% ``iterate'' procedure, and only the ``end'' procedure gets to know |
| 581 |
% how it all turned out. |
| 582 |
% |
| 583 |
% In many methods, some of these procedures do nothing at all. This is |
| 584 |
% then because there is nothing that needs to be done for that particular |
| 585 |
% method. |
| 586 |
% |
| 587 |
% \begin{proc}{multiupvar} |
| 588 |
% The |multiupvar| procedure does |upvar #0| for a number of |
| 589 |
% variables, prepending the namespace of the caller to each of the |
| 590 |
% \word{other-var} arguments of |upvar|. The syntax is |
| 591 |
% \begin{quote} |
| 592 |
% |eemenu::multiupvar| \word{my-var}\regplus |
| 593 |
% \end{quote} |
| 594 |
% \changes{v\,0.2}{2002/12/26}{Corrected a minor bug: one must look |
| 595 |
% at the first element in the list that info level returns. (LH)} |
| 596 |
% \begin{tcl} |
| 597 |
%<*!atcl7> |
| 598 |
proc eemenu::multiupvar {args} { |
| 599 |
foreach var $args {uplevel 1 [list variable $var]} |
| 600 |
} |
| 601 |
%</!atcl7> |
| 602 |
%<*atcl7> |
| 603 |
proc eemenu::multiupvar {args} { |
| 604 |
if {[info level]>1} then { |
| 605 |
set ns [lindex [info level -1] 0] |
| 606 |
set t [string last :: $ns] |
| 607 |
if {$t<0} then {set ns {}} else { |
| 608 |
set ns [string range $ns 0 [expr {$t+1}]] |
| 609 |
} |
| 610 |
} else {set ns {}} |
| 611 |
set t 1 |
| 612 |
set call [list upvar #0] |
| 613 |
foreach var $args {lappend call ${ns}${var} $var} |
| 614 |
uplevel 1 $call |
| 615 |
} |
| 616 |
%</atcl7> |
| 617 |
% \end{tcl} |
| 618 |
% \end{proc} |
| 619 |
% |
| 620 |
% |
| 621 |
% \subsection{The main executive} |
| 622 |
% |
| 623 |
% \begin{arrayvar}{cmdA}[command name] |
| 624 |
% The |cmdA| array stores all definitions of \eemenu\ commands. The |
| 625 |
% indices into the array are the command names. The entries are |
| 626 |
% key--value lists which contain the settings for the command. |
| 627 |
% |
| 628 |
% The \describestring[key]{active}|active|, |
| 629 |
% \describestring[key]{binding}|binding|, and |
| 630 |
% \describestring[key]{mode}|mode| keys have to do with the key |
| 631 |
% binding for this command. If |active| is |1| then the binding should |
| 632 |
% be made upon startup. |binding| is the actual binding to use. |mode| |
| 633 |
% is the mode for which the binding should be made; if this is |
| 634 |
% |<none>| then the binding should be global. |
| 635 |
% |
| 636 |
% The \describestring[key]{in_menu}|in_menu| key controls whether |
| 637 |
% this command should appear as a command in the main \textsf{EE} |
| 638 |
% menu. |
| 639 |
% |
| 640 |
% The \describestring[key]{extractor}|extractor|, |
| 641 |
% \describestring[key]{complete}|complete|, |
| 642 |
% \describestring[key]{evaluator}|evaluator|, and |
| 643 |
% \describestring[key]{reporter}|reporter| keys store the particular |
| 644 |
% methods that are used by the command. The values are prettified |
| 645 |
% method names. For each of these keys there is also an \dots|_extra| |
| 646 |
% key whose value is the key--value list of detail settings for that |
| 647 |
% method. The exact names are \describestring[key]{extract_extra} |
| 648 |
% |extract_extra|, \describestring[key]{complete_extra} |
| 649 |
% |complete_extra|, \describestring[key]{eval_extra}|eval_extra|, and |
| 650 |
% \describestring[key]{report_extra}|report_extra|. |
| 651 |
% |
| 652 |
% If the |cmdA| array isn't set then it will be initialised in |
| 653 |
% Section~\ref{Sec:DefCmdA}. |
| 654 |
% \end{arrayvar} |
| 655 |
% |
| 656 |
% |
| 657 |
% |
| 658 |
% \begin{proc}{main} |
| 659 |
% The |main| procedure is meant to be called from key binding scripts |
| 660 |
% and menu procs to actually carry out an \eemenu\ command. The |
| 661 |
% syntax is |
| 662 |
% \begin{quote} |
| 663 |
% |eemenu::main| \word{command name} \meta{selection-args} |
| 664 |
% \end{quote} |
| 665 |
% The \word{command name} is the name of the \eemenu\ command. The |
| 666 |
% \meta{selection-args} can be used to specify what the command |
| 667 |
% should extract from; they are passed straight on to the extraction |
| 668 |
% method |start| procedure. |
| 669 |
% |
| 670 |
% If there was an error during the execution of the command then |main| |
| 671 |
% terminates with an error. There is no particular result from this |
| 672 |
% procedure. |
| 673 |
% |
| 674 |
% The first part of |main| calls the begin procedures of the methods |
| 675 |
% used. |
| 676 |
% \begin{tcl} |
| 677 |
proc eemenu::main {command args} { |
| 678 |
global eemenu::cmdA |
| 679 |
if {![info exists eemenu::cmdA($command)]} then { |
| 680 |
error "Command '$command' undefined." |
| 681 |
} |
| 682 |
array set CMD [set eemenu::cmdA($command)] |
| 683 |
% \smallskip |
| 684 |
set extract [eemenu::Unprettify $CMD(extractor)] |
| 685 |
set cmpl [eemenu::Unprettify $CMD(complete)] |
| 686 |
set eval [eemenu::Unprettify $CMD(evaluator)] |
| 687 |
set report [eemenu::Unprettify $CMD(reporter)] |
| 688 |
% \smallskip |
| 689 |
set win\ |
| 690 |
[eval [list eemenu::${extract}::start $CMD(extract_extra)] $args] |
| 691 |
upvar #0 eemenu::${cmpl}::complete complete |
| 692 |
eemenu::${report}::log_open $CMD(report_extra) $win |
| 693 |
% \end{tcl} |
| 694 |
% The main part of |main| is the following loop over extracted lines. |
| 695 |
% The |res| variable stores the last result returned by the evaluation |
| 696 |
% method. The |safe| variable is a boolean for whether the current |
| 697 |
% position should be considered safe. The |lines| variable contains |
| 698 |
% the lines extracted but not yet evaluated. The |at_end| variable is |
| 699 |
% |0| until the end of the extractable portion of the code has been |
| 700 |
% encountered. |
| 701 |
% \begin{tcl} |
| 702 |
set res [eemenu::${eval}::begin $CMD(eval_extra) $win] |
| 703 |
eval [list eemenu::${report}::log_result] $res |
| 704 |
set lines [list] |
| 705 |
set safe 1 |
| 706 |
while {![lindex $res 0]} { |
| 707 |
% \end{tcl} |
| 708 |
% First extract the next line of code and append it to |lines|. |
| 709 |
% \begin{tcl} |
| 710 |
set at_end [catch {eemenu::${extract}::next $safe} line] |
| 711 |
if {$at_end == 1} then { |
| 712 |
global errorInfo |
| 713 |
return -code error -errorinfo $errorInfo |
| 714 |
} elseif {$at_end == 0} then { |
| 715 |
lappend lines $line |
| 716 |
} elseif {![llength $lines]} then {break} |
| 717 |
% \end{tcl} |
| 718 |
% Secondly check if there is a complete block of code in |lines|. |
| 719 |
% \begin{tcl} |
| 720 |
set safe [expr $complete] |
| 721 |
if {$at_end && !$safe} then { |
| 722 |
set safe [expr {![dialog::yesno -y No -n Yes\ |
| 723 |
"The last [llength $lines] lines do not appear to be a\ |
| 724 |
complete block of code. Evaluate anyway?"]}] |
| 725 |
if {!$safe} then { |
| 726 |
set res [list 1 "" ""] |
| 727 |
break |
| 728 |
} |
| 729 |
} |
| 730 |
% \end{tcl} |
| 731 |
% Finally log code, evaluate it, and log the result. This should |
| 732 |
% happen when |lines| contains a complete block of code. If there is |
| 733 |
% no error in evaluating the code then the current position will be |
| 734 |
% safe at the next iteration of the loop, and if there is an error |
| 735 |
% then the loop will not be iterated anyway. Hence the use of |safe| |
| 736 |
% is correct. |
| 737 |
% \begin{tcl} |
| 738 |
if {$safe} then { |
| 739 |
eemenu::${report}::log_code $lines |
| 740 |
set res [eemenu::${eval}::item $lines] |
| 741 |
eval [list eemenu::${report}::log_result] $res |
| 742 |
set lines [list] |
| 743 |
} |
| 744 |
} |
| 745 |
% \end{tcl} |
| 746 |
% If an error has already been detected then it doesn't matter if |
| 747 |
% |end| evaluates without error, but it could also be that no error |
| 748 |
% results are returned before |end|. |
| 749 |
% \begin{tcl} |
| 750 |
if {[lindex $res 0]} then { |
| 751 |
eval [list eemenu::${report}::log_result] [eemenu::${eval}::end] |
| 752 |
} else { |
| 753 |
set res [eemenu::${eval}::end] |
| 754 |
eval [list eemenu::${report}::log_result] $res |
| 755 |
} |
| 756 |
eemenu::${extract}::finish [lindex $res 0] |
| 757 |
eemenu::${report}::log_close |
| 758 |
} |
| 759 |
% \end{tcl} |
| 760 |
% \end{proc} |
| 761 |
% |
| 762 |
% |
| 763 |
% \subsection{The key bindings} |
| 764 |
% |
| 765 |
% There is a small system for managing the \eemenu\ key bindings. There |
| 766 |
% are two reasons for this: deactivating a command should only unbind a |
| 767 |
% binding if that binding is really currently used for that command, |
| 768 |
% and the \textsf{Active~Commands} submenu should match the actual |
| 769 |
% bindings. |
| 770 |
% |
| 771 |
% \begin{proc}{binding_index} |
| 772 |
% The |binding_index| procedure makes an index into the |binding| array. |
| 773 |
% The syntax is |
| 774 |
% \begin{quote} |
| 775 |
% |eemenu::binding_index| \word{mode} \word{binding} |
| 776 |
% \end{quote} |
| 777 |
% Both an empty string and |<none>| as \word{mode} are interpreted as |
| 778 |
% ``global''. |
| 779 |
% \begin{tcl} |
| 780 |
proc eemenu::binding_index {mode binding} { |
| 781 |
if {"<none>"==$mode} then {set mode ""} |
| 782 |
set mode [string range "[string trim $mode] " 0 3] |
| 783 |
return "$mode$binding" |
| 784 |
} |
| 785 |
% \end{tcl} |
| 786 |
% \end{proc} |
| 787 |
% |
| 788 |
% \begin{arrayvar}{binding} |
| 789 |
% The |binding| array is used to keep track of which command is |
| 790 |
% currently using a particular binding. The entries in this array are |
| 791 |
% command names. The indices have the form |
| 792 |
% \begin{quote} |
| 793 |
% \meta{mode}\meta{binding} |
| 794 |
% \end{quote} |
| 795 |
% where \meta{mode} is the mode and \meta{binding} is the menu-style |
| 796 |
% code for the binding. \meta{mode} is padded on the right with |
| 797 |
% spaces to exactly four characters. The \meta{mode} for global |
| 798 |
% bindings is four spaces. |
| 799 |
% \end{arrayvar} |
| 800 |
% |
| 801 |
% \begin{proc}{init_bindings} |
| 802 |
% The |init_bindings| procedure initialises the |binding| array and |
| 803 |
% the actual key bindings to match the data in the |cmdA| array. It |
| 804 |
% should be called when the menu is activated, but before the menu |
| 805 |
% itself is built. |
| 806 |
% \begin{tcl} |
| 807 |
proc eemenu::init_bindings {} { |
| 808 |
eemenu::multiupvar cmdA binding |
| 809 |
foreach cmd [array names cmdA] { |
| 810 |
% \end{tcl} |
| 811 |
% Only commands that are active needs to be considered. |
| 812 |
% \begin{tcl} |
| 813 |
array set A $cmdA($cmd) |
| 814 |
if {!$A(active)} then {continue} |
| 815 |
% \end{tcl} |
| 816 |
% The state of the binding must also be determined. It could be that |
| 817 |
% some other \textsf{EE~Menu} command is using the same binding, in |
| 818 |
% which case the user should be informed of this. |
| 819 |
% \begin{tcl} |
| 820 |
set idx [eemenu::binding_index $A(mode) $A(binding)] |
| 821 |
if {[info exists binding($idx)] &&\ |
| 822 |
![dialog::yesno "To activate '$cmd', I must first deativate\ |
| 823 |
'$binding($idx)'. Proceed?"]}\ |
| 824 |
% |
| 825 |
then {continue} |
| 826 |
% \end{tcl} |
| 827 |
% Now the binding can be made for the command. |
| 828 |
% \begin{tcl} |
| 829 |
set binding($idx) $cmd |
| 830 |
set call [keys::bindKey $A(binding)] |
| 831 |
lappend call [list eemenu::main $cmd] |
| 832 |
if {[string compare "<none>" $A(mode)]} then {lappend call $A(mode)} |
| 833 |
eval $call |
| 834 |
} |
| 835 |
} |
| 836 |
% \end{tcl} |
| 837 |
% \end{proc} |
| 838 |
% |
| 839 |
% \begin{proc}{deactivate} |
| 840 |
% The |deactivate| procedure has the syntax |
| 841 |
% \begin{quote} |
| 842 |
% |eemenu::deactivate| \word{\eemenu\ command}\regplus |
| 843 |
% \end{quote} |
| 844 |
% It deactivates the bindings for all commands listed as arguments |
| 845 |
% and updates the \textsf{Active Commands} submenu accordingly. |
| 846 |
% \begin{tcl} |
| 847 |
proc eemenu::deactivate {args} { |
| 848 |
eemenu::multiupvar binding cmdA |
| 849 |
foreach cmd $args { |
| 850 |
% \end{tcl} |
| 851 |
% First make sure the binding is actually active. |
| 852 |
% \begin{tcl} |
| 853 |
array set A $cmdA($cmd) |
| 854 |
set idx [eemenu::binding_index $A(mode) $A(binding)] |
| 855 |
if {![info exists binding($idx)] ||\ |
| 856 |
[string compare $binding($idx) $cmd]} then {continue} |
| 857 |
% \end{tcl} |
| 858 |
% Then unset everything that has to do with it. |
| 859 |
% \begin{tcl} |
| 860 |
unset binding($idx) |
| 861 |
set call [keys::unbindKey $A(binding)] |
| 862 |
lappend call "" |
| 863 |
if {[string compare "<none>" $A(mode)]} then {lappend call $A(mode)} |
| 864 |
eval $call |
| 865 |
markMenuItem -m "Active Commands" $cmd off |
| 866 |
} |
| 867 |
} |
| 868 |
% \end{tcl} |
| 869 |
% \end{proc} |
| 870 |
% |
| 871 |
% \begin{proc}{activate} |
| 872 |
% The |activate| procedure activates the bindings for the \eemenu\ |
| 873 |
% commands listed as arguments. It has the syntax |
| 874 |
% \begin{quote} |
| 875 |
% |eemenu::activate| \word{noisy} \word{\eemenu\ command}\regplus |
| 876 |
% \end{quote} |
| 877 |
% The procedure notices and handles the case that the binding for an |
| 878 |
% already active command coincides with that of some command to |
| 879 |
% activate, usually by deactivating the active command. The \word{noisy} |
| 880 |
% argument controls how it will behave in this. If \word{noisy} is |0| |
| 881 |
% then it will merely show a list of deactivations on the status bar, |
| 882 |
% but if it is |1| then it will put up a dialog and ask first. |
| 883 |
% \begin{tcl} |
| 884 |
proc eemenu::activate {noisy args} { |
| 885 |
eemenu::multiupvar binding cmdA |
| 886 |
set deactiveL [list] |
| 887 |
foreach cmd $args { |
| 888 |
% \end{tcl} |
| 889 |
% First determine the state of the binding. |
| 890 |
% \begin{tcl} |
| 891 |
array set A $cmdA($cmd) |
| 892 |
set idx [eemenu::binding_index $A(mode) $A(binding)] |
| 893 |
if {[info exists binding($idx)]} then { |
| 894 |
if {![string compare $binding($idx) $cmd]} then {continue} |
| 895 |
% \end{tcl} |
| 896 |
% In this case the binding is being used by some other command. |
| 897 |
% Should that be deactivated? |
| 898 |
% \begin{tcl} |
| 899 |
if {$noisy && ![dialog::yesno "To activate '$cmd', I must\ |
| 900 |
first deativate '$binding($idx)'. Proceed?"]} then {continue} |
| 901 |
% \end{tcl} |
| 902 |
% Here we know it should. Deactivation can be simplified since the |
| 903 |
% binding will anyway be overwritten later. |
| 904 |
% \begin{tcl} |
| 905 |
lappend deactiveL $binding($idx) |
| 906 |
markMenuItem -m "Active Commands" $binding($idx) off |
| 907 |
} |
| 908 |
% \end{tcl} |
| 909 |
% Now activate the binding, as was the original intention. |
| 910 |
% \begin{tcl} |
| 911 |
set binding($idx) $cmd |
| 912 |
set call [keys::bindKey $A(binding)] |
| 913 |
lappend call [list eemenu::main $cmd] |
| 914 |
if {[string compare "<none>" $A(mode)]} then {lappend call $A(mode)} |
| 915 |
eval $call |
| 916 |
markMenuItem -m "Active Commands" $binding($idx) on\ |
| 917 |
[text::Ascii 18 1] |
| 918 |
} |
| 919 |
if {!$noisy && [llength $deactiveL]} then { |
| 920 |
status::msg "Deactivated commands: [join $deactiveL ", "]" |
| 921 |
} |
| 922 |
} |
| 923 |
% \end{tcl} |
| 924 |
% \end{proc} |
| 925 |
% |
| 926 |
% |
| 927 |
% \subsection{Building and handling the menu} |
| 928 |
% |
| 929 |
% \begin{proc}{build_menu} |
| 930 |
% The |build_menu| procedure builds the menu. It is called when the |
| 931 |
% menu is initially created and whenever some command settings have |
| 932 |
% been edited. |
| 933 |
% \begin{tcl} |
| 934 |
proc eemenu::build_menu {} { |
| 935 |
eemenu::multiupvar cmdA binding |
| 936 |
set items [list "Edit Commands[text::Ascii 201 1]"] |
| 937 |
if {[array size cmdA] > 0} then { |
| 938 |
%<atcl7> set cmdL [lsort -ignore [array names cmdA]] |
| 939 |
%<!atcl7> set cmdL [lsort -dictionary [array names cmdA]] |
| 940 |
lappend items [list Menu -n "Active Commands" -m\ |
| 941 |
-p eemenu::menu_proc $cmdL] |
| 942 |
lappend items "(-)" |
| 943 |
foreach cmd $cmdL { |
| 944 |
array set A $cmdA($cmd) |
| 945 |
if {$A(in_menu)} then {lappend items $cmd} |
| 946 |
} |
| 947 |
} |
| 948 |
global eeMenu |
| 949 |
Menu -n $eeMenu -m -p eemenu::menu_proc $items |
| 950 |
if {[array size cmdA]} then { |
| 951 |
foreach idx [array names binding] { |
| 952 |
markMenuItem -m "Active Commands" $binding($idx) on\ |
| 953 |
[text::Ascii 18 1] |
| 954 |
} |
| 955 |
} |
| 956 |
} |
| 957 |
% \end{tcl} |
| 958 |
% \end{proc} |
| 959 |
% |
| 960 |
% \begin{proc}{menu_proc} |
| 961 |
% The |menu_proc| handles selection of items in the \emph{EE} menu and |
| 962 |
% its submenu. The syntax is the standard |
| 963 |
% \begin{quote} |
| 964 |
% |eemenu::menu_proc| \word{menu} \word{item} |
| 965 |
% \end{quote} |
| 966 |
% \begin{tcl} |
| 967 |
proc eemenu::menu_proc {menu item} { |
| 968 |
global eeMenu |
| 969 |
eemenu::multiupvar cmdA binding |
| 970 |
switch -- $menu $eeMenu { |
| 971 |
switch -- $item "Edit Commands" { |
| 972 |
eemenu::edit_commands |
| 973 |
} default { |
| 974 |
eemenu::main $item |
| 975 |
} |
| 976 |
} "Active Commands" { |
| 977 |
array set A $cmdA($item) |
| 978 |
set idx [eemenu::binding_index $A(mode) $A(binding)] |
| 979 |
if {[info exists binding($idx)] &&\ |
| 980 |
![string compare $binding($idx) $item]} then { |
| 981 |
eemenu::deactivate $item |
| 982 |
} else { |
| 983 |
eemenu::activate 1 $item |
| 984 |
} |
| 985 |
} |
| 986 |
} |
| 987 |
% \end{tcl} |
| 988 |
% \end{proc} |
| 989 |
% |
| 990 |
% |
| 991 |
% \subsection{The command dialogs} |
| 992 |
% \label{Ssec:CmdDialogs} |
| 993 |
% |
| 994 |
% The dialog for editing command settings has two levels. On the top |
| 995 |
% level, the dialog has one page per command. This dialog allows one to |
| 996 |
% select methods, but does not show any detail settings for the methods. |
| 997 |
% The other level has one page for each method type (or less) and shows |
| 998 |
% only the detail settings for that method. |
| 999 |
% |
| 1000 |
% \begin{arrayvar}{detail_typeA} |
| 1001 |
% \begin{arrayvar}{detail_helpA} |
| 1002 |
% \begin{arrayvar}{detail_keyA} |
| 1003 |
% The |detail_typeA| and |detail_helpA| arrays define the items in the |
| 1004 |
% setting details dialog. They are sent as arguments to |
| 1005 |
% |dialog::handle|, and thus the indices have the form |
| 1006 |
% \meta{page}|,|\meta{name}. The \meta{page} is either |Extract| |
| 1007 |
% for the extraction method page, |Complete| for the completion |
| 1008 |
% method page, |Evaluate| for the evaulation method page, or |Report| |
| 1009 |
% for the report method page. The |detail_keyA| array gives the keys |
| 1010 |
% associated with the items. |
| 1011 |
% \end{arrayvar}\end{arrayvar}\end{arrayvar} |
| 1012 |
% |
| 1013 |
% \begin{arrayvar}{detail_defaultA} |
| 1014 |
% The |detail_defaultA| array is indexed by the name of a detail page |
| 1015 |
% (|Extract|, |Complete|, |Evaluate|, or |Report|). The entries are |
| 1016 |
% key--value lists that constitute suggested defaults for the |
| 1017 |
% \dots|_extra| items in the main dialog. |
| 1018 |
% \begin{tcl} |
| 1019 |
array set eemenu::detail_defaultA\ |
| 1020 |
{Extract {} Complete {} Evaluate {} Report {}} |
| 1021 |
% \end{tcl} |
| 1022 |
% \end{arrayvar} |
| 1023 |
% |
| 1024 |
% \begin{proc}{define_detail} |
| 1025 |
% The |define_detail| procedure is a helper to simplify the definition |
| 1026 |
% of items in the detail dialogs by handling internally all the odd |
| 1027 |
% variable names that are involved. The syntax is |
| 1028 |
% \begin{quote} |
| 1029 |
% |eemenu::define_detail| \word{page} \word{name} \word{key} |
| 1030 |
% \word{type} \word{value}\regopt\ \word{help}\regopt |
| 1031 |
% \end{quote} |
| 1032 |
% \word{page} and \word{name} specify the item. \word{key}, |
| 1033 |
% \word{type}, \word{value}, and \word{help} are what will be stored |
| 1034 |
% into the arrays. The return value is precisely \word{name}, so that |
| 1035 |
% one can put that in the |extract|, |complete|, |evaluate|, or |
| 1036 |
% |report| array in the same command as the item is defined. |
| 1037 |
% |
| 1038 |
% It is OK to define the same item several times, provided that the |
| 1039 |
% definitions are equal (or different only in the \word{value}s or |
| 1040 |
% in that one has a \word{help} and the other doesn't), but it is an |
| 1041 |
% error if they are different. |
| 1042 |
% \begin{tcl} |
| 1043 |
proc eemenu::define_detail {page name key type {val ""} {help ""}} { |
| 1044 |
upvar #0 eemenu::detail_typeA typeA eemenu::detail_helpA helpA\ |
| 1045 |
eemenu::detail_keyA keyA eemenu::detail_defaultA valA |
| 1046 |
set error "" |
| 1047 |
set idx "$page,$name" |
| 1048 |
if {![info exists keyA($idx)]} then { |
| 1049 |
set keyA($idx) $key |
| 1050 |
} elseif {"$key" != "$keyA($idx)"} then { |
| 1051 |
append error " Different keys: '$keyA($idx)' and '$key'." |
| 1052 |
} |
| 1053 |
if {![info exists typeA($idx)]} then { |
| 1054 |
set typeA($idx) $type |
| 1055 |
} elseif {"$type" != "$typeA($idx)"} then { |
| 1056 |
append error " Different types: '$typeA($idx)' and '$type'." |
| 1057 |
} |
| 1058 |
if {[string length $val]} then { |
| 1059 |
if {[info exists valA($page)]} then {array set A $valA($page)} |
| 1060 |
if {![info exists A($key)] || ![string length $A($key)]} then { |
| 1061 |
set A($key) $val |
| 1062 |
set valA($page) [array get A] |
| 1063 |
} |
| 1064 |
} |
| 1065 |
if {[string length $help]} then { |
| 1066 |
if {![info exists helpA($idx)]} then { |
| 1067 |
set helpA($idx) $help |
| 1068 |
} elseif {"$help" != "$helpA($idx)"} then { |
| 1069 |
append error " Different help texts: '$helpA($idx)' and '$help'." |
| 1070 |
} |
| 1071 |
} |
| 1072 |
if {[string length $error]} then { |
| 1073 |
dialog::alert "The detail setting '$name' for '$page' methods\ |
| 1074 |
has conficting definitions.$error This is an error that should |
| 1075 |
be fixed; for now, the second definition will be ignored." |
| 1076 |
} |
| 1077 |
return $name |
| 1078 |
} |
| 1079 |
% \end{tcl} |
| 1080 |
% \end{proc} |
| 1081 |
% |
| 1082 |
% |
| 1083 |
% \begin{proc}{edit_commands} |
| 1084 |
% The |edit_commands| procedure puts up a dialog that lets the user |
| 1085 |
% edit the command settings. It takes no arguments and returns nothing. |
| 1086 |
% \begin{tcl} |
| 1087 |
proc eemenu::edit_commands {} { |
| 1088 |
global eemenu::extract eemenu::complete eemenu::evaluate\ |
| 1089 |
eemenu::report |
| 1090 |
% \end{tcl} |
| 1091 |
% The first thing to do is to determine the layout for command pages. |
| 1092 |
% \begin{tcl} |
| 1093 |
set layout [list] |
| 1094 |
lappend layout [list active flag Active "Is the binding active?"] |
| 1095 |
lappend layout [list binding binding "Command keybinding"] |
| 1096 |
lappend layout [list mode mode "Binding mode"] |
| 1097 |
lappend layout [list in_menu flag "Put in menu"] |
| 1098 |
% \smallskip |
| 1099 |
%<*atcl7> |
| 1100 |
set M [list] |
| 1101 |
foreach method [lsort -ignore [array names eemenu::extract]] { |
| 1102 |
lappend M [eemenu::Prettify $method] |
| 1103 |
} |
| 1104 |
lappend layout [list extractor [list menu $M] "Extraction method"] |
| 1105 |
lappend layout [list extract_extra [list hidden keyval] extract_extra] |
| 1106 |
% \smallskip |
| 1107 |
set M [list] |
| 1108 |
foreach method [lsort -ignore [array names eemenu::complete]] { |
| 1109 |
lappend M [eemenu::Prettify $method] |
| 1110 |
} |
| 1111 |
lappend layout [list complete [list menu $M] "Completion test"] |
| 1112 |
lappend layout [list complete_extra [list hidden keyval] complete_extra] |
| 1113 |
% \smallskip |
| 1114 |
set M [list] |
| 1115 |
foreach method [lsort -ignore [array names eemenu::evaluate]] { |
| 1116 |
lappend M [eemenu::Prettify $method] |
| 1117 |
} |
| 1118 |
lappend layout [list evaluator [list menu $M] "Evaluation method"] |
| 1119 |
lappend layout [list eval_extra [list hidden keyval] eval_extra] |
| 1120 |
% \smallskip |
| 1121 |
set M [list] |
| 1122 |
foreach method [lsort -ignore [array names eemenu::report]] { |
| 1123 |
lappend M [eemenu::Prettify $method] |
| 1124 |
} |
| 1125 |
lappend layout [list reporter [list menu $M] "Report method"] |
| 1126 |
lappend layout [list report_extra [list hidden keyval] report_extra] |
| 1127 |
%</atcl7> |
| 1128 |
%<*!atcl7> |
| 1129 |
set M [list] |
| 1130 |
foreach method [lsort -dictionary [array names eemenu::extract]] { |
| 1131 |
lappend M [eemenu::Prettify $method] |
| 1132 |
} |
| 1133 |
lappend layout [list extractor [list menu $M] "Extraction method"] |
| 1134 |
lappend layout [list extract_extra [list hidden keyval] extract_extra] |
| 1135 |
% \smallskip |
| 1136 |
set M [list] |
| 1137 |
foreach method [lsort -dictionary [array names eemenu::complete]] { |
| 1138 |
lappend M [eemenu::Prettify $method] |
| 1139 |
} |
| 1140 |
lappend layout [list complete [list menu $M] "Completion test"] |
| 1141 |
lappend layout [list complete_extra [list hidden keyval] complete_extra] |
| 1142 |
% \smallskip |
| 1143 |
set M [list] |
| 1144 |
foreach method [lsort -dictionary [array names eemenu::evaluate]] { |
| 1145 |
lappend M [eemenu::Prettify $method] |
| 1146 |
} |
| 1147 |
lappend layout [list evaluator [list menu $M] "Evaluation method"] |
| 1148 |
lappend layout [list eval_extra [list hidden keyval] eval_extra] |
| 1149 |
% \smallskip |
| 1150 |
set M [list] |
| 1151 |
foreach method [lsort -dictionary [array names eemenu::report]] { |
| 1152 |
lappend M [eemenu::Prettify $method] |
| 1153 |
} |
| 1154 |
lappend layout [list reporter [list menu $M] "Report method"] |
| 1155 |
lappend layout [list report_extra [list hidden keyval] report_extra] |
| 1156 |
%</!atcl7> |
| 1157 |
% \end{tcl} |
| 1158 |
% Then the call to |dialog::make_paged| can be constructed (in the |
| 1159 |
% |call| variable), but as it is convenient to do that in order, the |
| 1160 |
% page arguments (which are the easiest) will be constructed last. |
| 1161 |
% \begin{tcl} |
| 1162 |
global dialog::ellipsis |
| 1163 |
if {![info exists dialog::ellipsis]} then {auto_load dialog::make_paged} |
| 1164 |
set call [list dialog::make_paged] |
| 1165 |
set buttons [list] |
| 1166 |
lappend buttons "New${dialog::ellipsis}" "Add new command"\ |
| 1167 |
{eemenu::add_command ""} |
| 1168 |
lappend buttons "Duplicate${dialog::ellipsis}"\ |
| 1169 |
"Duplicate this command" {eemenu::add_command $currentpage} |
| 1170 |
lappend buttons "Rename${dialog::ellipsis}"\ |
| 1171 |
"Rename this command" {eemenu::rename_command} |
| 1172 |
lappend buttons "Delete${dialog::ellipsis}"\ |
| 1173 |
"Delete this command" { |
| 1174 |
if {[dialog::yesno "Are you sure you want to\ |
| 1175 |
delete '$currentpage'?"]} { |
| 1176 |
set pages [dialog::delete_pages $pages\ |
| 1177 |
[list $currentpage] delta_pages] |
| 1178 |
} |
| 1179 |
} |
| 1180 |
lappend buttons "Details${dialog::ellipsis}"\ |
| 1181 |
"Setting details for this command" { |
| 1182 |
eemenu::command_details $dial $currentpage |
| 1183 |
} |
| 1184 |
lappend call -addbuttons $buttons -changeditems mods\ |
| 1185 |
-alpha7pagelimit 2 |
| 1186 |
% \end{tcl} |
| 1187 |
% Finally the page arguments to |dialog::make_paged| can be appended |
| 1188 |
% and the actuall call made. |
| 1189 |
% \begin{tcl} |
| 1190 |
global eemenu::cmdA |
| 1191 |
%<atcl7> foreach cmd [lsort -ignore [array names eemenu::cmdA]] { |
| 1192 |
%<!atcl7> foreach cmd [lsort -dictionary [array names eemenu::cmdA]] { |
| 1193 |
lappend call [list $cmd [set eemenu::cmdA($cmd)] $layout] |
| 1194 |
} |
| 1195 |
set res [eval $call] |
| 1196 |
% \end{tcl} |
| 1197 |
% If |make_paged| terminates with an error (the user pressed |
| 1198 |
% \textsf{Cancel}) then processing of this procedure should stop here. |
| 1199 |
% Thus the |eval| above is quite in order. |
| 1200 |
% |
| 1201 |
% After that, the settings should be updated. The first step is to |
| 1202 |
% deactivate those commands whose activation state, binding, or mode |
| 1203 |
% has changed, since that has to be done before the old settings |
| 1204 |
% are cleared. |
| 1205 |
% \begin{tcl} |
| 1206 |
set call [list eemenu::deactivate] |
| 1207 |
newforeach {cmd keys} $mods { |
| 1208 |
if {[lsearch -regexp $keys {^(active|binding|mode)$}]>=0 &&\ |
| 1209 |
[info exists eemenu::cmdA($cmd)]} then { |
| 1210 |
lappend call $cmd |
| 1211 |
} |
| 1212 |
} |
| 1213 |
if {[llength $call]>1} then {eval $call} |
| 1214 |
% \end{tcl} |
| 1215 |
% Now the new settings can replace the old. |
| 1216 |
% \begin{tcl} |
| 1217 |
unset eemenu::cmdA |
| 1218 |
array set eemenu::cmdA $res |
| 1219 |
% \end{tcl} |
| 1220 |
% Then what remains is (i) to inform \Alpha\ that the changed command |
| 1221 |
% settings need to be saved, (ii) to make bindings for those commands |
| 1222 |
% that are active, and (iii) to add or remove items from the menu. |
| 1223 |
% \begin{tcl} |
| 1224 |
set call [list eemenu::activate 0] |
| 1225 |
set build_menu 0 |
| 1226 |
%<atcl7> newforeach {cmd keys} $mods { |
| 1227 |
%<!atcl7> foreach {cmd keys} $mods { |
| 1228 |
prefs::modified eemenu::cmdA($cmd) |
| 1229 |
if {![info exists eemenu::cmdA($cmd)]}\ |
| 1230 |
then {set build_menu 1; continue} |
| 1231 |
array set A [set eemenu::cmdA($cmd)] |
| 1232 |
if {$A(active) &&\ |
| 1233 |
[lsearch -regexp $keys {^(active|binding|mode)$}]>=0}\ |
| 1234 |
then {lappend call $cmd} |
| 1235 |
if {[lsearch -exact $keys in_menu]>=0} then {set build_menu 1} |
| 1236 |
} |
| 1237 |
if {[llength $call]>2} then {eval $call} |
| 1238 |
if {$build_menu} then {eemenu::build_menu} |
| 1239 |
} |
| 1240 |
% \end{tcl} |
| 1241 |
% The conditions used above rely to some extent on the fact that |
| 1242 |
% \emph{all} items on a dialog page that is added or deleted count as |
| 1243 |
% having been changed. |
| 1244 |
% \end{proc} |
| 1245 |
% |
| 1246 |
% \begin{proc}{add_command} |
| 1247 |
% The |add_command| procedure is called by a button script to add a |
| 1248 |
% new command page to the dialog. The syntax is |
| 1249 |
% \begin{quote} |
| 1250 |
% |eemenu::add_command| \word{template} |
| 1251 |
% \end{quote} |
| 1252 |
% where \word{template} is the name of a command whose settings should |
| 1253 |
% be copied, or an empty string if the default settings should be used. |
| 1254 |
% \begin{tcl} |
| 1255 |
proc eemenu::add_command {templ} { |
| 1256 |
set name [getline "Name of new command"] |
| 1257 |
if {![string length $name]} then {return} |
| 1258 |
%<atcl7> newforeach {page items} [uplevel 1 {set pages}] { |
| 1259 |
%<!atcl7> foreach {page items} [uplevel 1 {set pages}] { |
| 1260 |
if {![string compare $page $name]} then { |
| 1261 |
alternote "That name is already in use!" |
| 1262 |
return |
| 1263 |
} |
| 1264 |
} |
| 1265 |
% \end{tcl} |
| 1266 |
% By default, make new commands inactive and don't put them in the |
| 1267 |
% menu. This is to avoid silly errors in case the user wants to do |
| 1268 |
% a ``backup'' of a command. |
| 1269 |
% \begin{tcl} |
| 1270 |
set keyvals [list active 0 in_menu 0] |
| 1271 |
if {[string length $templ]} then { |
| 1272 |
set dial [uplevel 1 {set dial}] |
| 1273 |
set cpage [uplevel 1 {set currentpage}] |
| 1274 |
%<atcl7> newforeach {key item}\ |
| 1275 |
%<!atcl7> foreach {key item}\ |
| 1276 |
{binding {Command keybinding} mode {Binding mode} |
| 1277 |
extractor {Extraction method} extract_extra extract_extra |
| 1278 |
complete {Completion test} complete_extra complete_extra |
| 1279 |
evaluator {Evaluation method} eval_extra eval_extra |
| 1280 |
reporter {Report method} report_extra report_extra} { |
| 1281 |
lappend keyvals $key [dialog::valGet $dial "${cpage},${item}"] |
| 1282 |
} |
| 1283 |
} else { |
| 1284 |
lappend keyvals binding "" mode "" extractor "Raw" |
| 1285 |
upvar #0 eemenu::detail_defaultA defaultA |
| 1286 |
lappend keyvals extract_extra $defaultA(Extract) |
| 1287 |
lappend keyvals complete "Entire Selection" complete_extra\ |
| 1288 |
$defaultA(Complete) |
| 1289 |
lappend keyvals evaluator "Internal Tcl" eval_extra\ |
| 1290 |
$defaultA(Evaluate) |
| 1291 |
lappend keyvals reporter "Status Line" report_extra $defaultA(Report) |
| 1292 |
} |
| 1293 |
uplevel 1 [list dialog::add_page $name $keyvals [uplevel 2 set layout]] |
| 1294 |
uplevel 1 [list set currentpage $name] |
| 1295 |
} |
| 1296 |
% \end{tcl} |
| 1297 |
% \end{proc} |
| 1298 |
% |
| 1299 |
% \begin{proc}{rename_command} |
| 1300 |
% The |rename_command| procedure is called by a button script to rename |
| 1301 |
% an existing command. There are no arguments. |
| 1302 |
% \begin{tcl} |
| 1303 |
proc eemenu::rename_command {} { |
| 1304 |
upvar 1 currentpage cpage dial dial |
| 1305 |
set name [getline "New name for command '$cpage'"] |
| 1306 |
if {![string length $name]} then {return} |
| 1307 |
%<atcl7> newforeach {page items} [uplevel 1 {set pages}] { |
| 1308 |
%<!atcl7> foreach {page items} [uplevel 1 {set pages}] { |
| 1309 |
if {![string compare $page $name]} then { |
| 1310 |
alternote "That name is already in use!" |
| 1311 |
return |
| 1312 |
} |
| 1313 |
} |
| 1314 |
% \end{tcl} |
| 1315 |
% Technically, the page with the old name is deleted and a new page |
| 1316 |
% with the new name is added. The keyvals have to saved to a list in |
| 1317 |
% between. |
| 1318 |
% \begin{tcl} |
| 1319 |
set keyvals [list] |
| 1320 |
%<atcl7> newforeach {key item} {active Active in_menu {Put in menu}\ |
| 1321 |
%<!atcl7> foreach {key item} {active Active in_menu {Put in menu}\ |
| 1322 |
binding {Command keybinding} mode {Binding mode}\ |
| 1323 |
extractor {Extraction method} extract_extra extract_extra\ |
| 1324 |
complete {Completion test} complete_extra complete_extra\ |
| 1325 |
evaluator {Evaluation method} eval_extra eval_extra\ |
| 1326 |
reporter {Report method} report_extra report_extra} { |
| 1327 |
lappend keyvals $key [dialog::valGet $dial "${cpage},${item}"] |
| 1328 |
} |
| 1329 |
uplevel 1 { |
| 1330 |
set pages [dialog::delete_pages $pages [list $currentpage]\ |
| 1331 |
delta_pages] |
| 1332 |
} |
| 1333 |
uplevel 1 [list dialog::add_page $name $keyvals [uplevel 2 set layout]] |
| 1334 |
set cpage $name |
| 1335 |
} |
| 1336 |
% \end{tcl} |
| 1337 |
% \end{proc} |
| 1338 |
% |
| 1339 |
% \begin{proc}{command_details} |
| 1340 |
% The |command_details| procedure is called by a button script to let |
| 1341 |
% the user see and edit the details of a command. The syntax is |
| 1342 |
% \begin{quote} |
| 1343 |
% |eemenu::command_details| \word{dialog ref.} \word{command} |
| 1344 |
% \end{quote} |
| 1345 |
% The \word{dialog ref.} is the reference to pass on to |
| 1346 |
% |dialog::valGet| and the like, as that is the only way to access the |
| 1347 |
% data that should be shown in the dialog. The \word{command} is the |
| 1348 |
% name of the command whose details should be shown, which is also the |
| 1349 |
% \meta{page} part of the array index that |dialog::valGet| needs. |
| 1350 |
% |
| 1351 |
% Most of this procedure consists of moving data from the data |
| 1352 |
% structures of one dialog to those of another, and back again. More |
| 1353 |
% precisely, data is taken from the \dots|_extra| items in the main |
| 1354 |
% dialog and put (using |array set|) into the local arrays |A1|, |A2|, |
| 1355 |
% |A3|, and |A4|. Then those entries in these arrays which correspond |
| 1356 |
% to details for the current set of methods are stored as dialog item |
| 1357 |
% values for |dial2|. At the end, those |dial2| items values that were |
| 1358 |
% changed are copied back to the corresponding |A| array, and then |
| 1359 |
% these arrays are put back (using |array get|) into the corresponding |
| 1360 |
% \dots|_extra| items in the main dialog. |
| 1361 |
% |
| 1362 |
% At the same time as the data are copied from the main dialog to the |
| 1363 |
% details dialog, the list of pages and items in the latter is being |
| 1364 |
% built. The information about this is taken from the |extract|, |
| 1365 |
% |complete|, |evaluate|, and |report| arrays. |
| 1366 |
% \begin{tcl} |
| 1367 |
proc eemenu::command_details {dial command} { |
| 1368 |
global eemenu::detail_typeA eemenu::detail_helpA\ |
| 1369 |
eemenu::detail_keyA eemenu::extract eemenu::complete\ |
| 1370 |
eemenu::evaluate eemenu::report |
| 1371 |
set pages [list] |
| 1372 |
set dial2 [dialog::create] |
| 1373 |
% \end{tcl} |
| 1374 |
% Exactly the same processing is done for all four pages of the |
| 1375 |
% details dialog, but since the location of the source data varies a |
| 1376 |
% bit irregularly between the pages, it is easiest to make a table of |
| 1377 |
% which variables and indices should be used. There is one line per |
| 1378 |
% page in the |newforeach| below. |
| 1379 |
% \begin{tcl} |
| 1380 |
%<atcl7> newforeach {which page layoutarr data arr} { |
| 1381 |
%<!atcl7> foreach {which page layoutarr data arr} { |
| 1382 |
{Extraction method} Extract eemenu::extract extract_extra A1 |
| 1383 |
{Completion test} Complete eemenu::complete complete_extra A2 |
| 1384 |
{Evaluation method} Evaluate eemenu::evaluate eval_extra A3 |
| 1385 |
{Report method} Report eemenu::report report_extra A4 |
| 1386 |
} { |
| 1387 |
set method [eemenu::Unprettify\ |
| 1388 |
[dialog::valGet $dial ${command},${which}]] |
| 1389 |
set L [set ${layoutarr}($method)] |
| 1390 |
if {[llength $L]} then { |
| 1391 |
lappend pages $page $L |
| 1392 |
array set $arr [dialog::valGet $dial ${command},${data}] |
| 1393 |
foreach l $L { |
| 1394 |
set v [set eemenu::detail_keyA($page,$l)] |
| 1395 |
if {[info exists ${arr}($v)]} then { |
| 1396 |
dialog::valSet $dial2 "$page,$l" [set ${arr}($v)] |
| 1397 |
} else { |
| 1398 |
% \end{tcl} |
| 1399 |
% It turns out \AlphaEight\ doesn't like an empty string as value for |
| 1400 |
% a checkbox, so the value is explicitly set to |0| for flags. |
| 1401 |
% \changes{v\,0.3}{2003/04/11}{Added special default for flag items. |
| 1402 |
% A similar fix should be put in the dialogs code. (LH)} |
| 1403 |
% \begin{tcl} |
| 1404 |
switch -- [set eemenu::detail_typeA($page,$l)] flag { |
| 1405 |
dialog::valSet $dial2 "$page,$l" 0 |
| 1406 |
} default { |
| 1407 |
dialog::valSet $dial2 "$page,$l" "" |
| 1408 |
} |
| 1409 |
} |
| 1410 |
} |
| 1411 |
} |
| 1412 |
} |
| 1413 |
% \smallskip |
| 1414 |
if {![llength $pages]} then { |
| 1415 |
dialog::alert "There are no details for these methods." |
| 1416 |
dialog::cleanup $dial2 |
| 1417 |
return |
| 1418 |
} |
| 1419 |
dialog::handle $pages eemenu::detail_typeA $dial2\ |
| 1420 |
eemenu::detail_helpA page [list]\ |
| 1421 |
[list [list "Back" "Return to overall dialog" ""] right first] |
| 1422 |
% \smallskip |
| 1423 |
set L [dialog::changed_items $dial2] |
| 1424 |
foreach item $L { |
| 1425 |
switch -glob $item { |
| 1426 |
Extract,* {set arr A1} |
| 1427 |
Complete,* {set arr A2} |
| 1428 |
Evaluate,* {set arr A3} |
| 1429 |
Report,* {set arr A4} |
| 1430 |
} |
| 1431 |
set ${arr}([set eemenu::detail_keyA($item)])\ |
| 1432 |
[dialog::valGet $dial2 $item] |
| 1433 |
} |
| 1434 |
%<atcl7> newforeach {page data arr} { |
| 1435 |
%<!atcl7> foreach {page data arr} { |
| 1436 |
Extract extract_extra A1 |
| 1437 |
Complete complete_extra A2 |
| 1438 |
Evaluate eval_extra A3 |
| 1439 |
Report report_extra A4 |
| 1440 |
} { |
| 1441 |
if {[lsearch -glob $L "${page},*"] >= 0} then { |
| 1442 |
dialog::valChanged $dial "${command},${data}" [array get $arr] |
| 1443 |
} |
| 1444 |
} |
| 1445 |
dialog::cleanup $dial2 |
| 1446 |
} |
| 1447 |
% \end{tcl} |
| 1448 |
% \end{proc} |
| 1449 |
% |
| 1450 |
% |
| 1451 |
% \subsection{\texttt{dialogsNew} patch} |
| 1452 |
% |
| 1453 |
% In the testing stage, I discovered that the |edit_commands| procedure |
| 1454 |
% managed to overstress \Alpha7's |dialog| command almost without |
| 1455 |
% trying. It is probably the large number of popup menus that is causing |
| 1456 |
% trouble, but regardless of the cause, I found that I couldn't use this |
| 1457 |
% dialog if it tried to show more than two commands. |
| 1458 |
% |
| 1459 |
% The \textsf{Edit Filesets} command faces a similar limitation and to |
| 1460 |
% work around that there is a separate \textsf{Edit A Fileset} command. |
| 1461 |
% As I didn't feel that much like reconstructing the \textsf{Edit |
| 1462 |
% Commands} dialog however, I instead redesigned |dialog::make_paged| |
| 1463 |
% so that \emph{it} automatically splits the dialog when there are too |
| 1464 |
% many pages in it. The redesigned |make_paged| will however probably |
| 1465 |
% not make it into Alpha\Tcllogo\ before v\,7.6d3 and at the moment |
| 1466 |
% that seems like a bit restrictive to me. Hence \emph{EE~Menu} will |
| 1467 |
% patch the \texttt{dialogsNew} code if this change hasn't already |
| 1468 |
% been incorporated. |
| 1469 |
% |
| 1470 |
% \begin{tcl} |
| 1471 |
%<*dialogspatch&atcl7> |
| 1472 |
if {![llength [info commands dialog::make_paged]]} then { |
| 1473 |
auto_load dialog::make_paged |
| 1474 |
} |
| 1475 |
if {![regexp -- -alpha7pagelimit [info body dialog::make_paged]]} then { |
| 1476 |
% \end{tcl} |
| 1477 |
% The following is copied from \texttt{dialogsNew.dtx} v\,1.4. |
| 1478 |
% |
| 1479 |
% \setnamespace{dialog} |
| 1480 |
% |
| 1481 |
% \begin{proc}{make_paged} |
| 1482 |
% The |make_paged| procedure is similar to the |make| procedure, but |
| 1483 |
% its argument argument structure is slightly different, its return |
| 1484 |
% value is very different, and it does have a couple of features that |
| 1485 |
% |make| doesn't (such as adding or removing pages or items in a |
| 1486 |
% dialog). The basic syntax is the same |
| 1487 |
% \begin{quote} |
| 1488 |
% |dialog::make_paged| \meta{option}\regstar\ \word{page}\regplus |
| 1489 |
% \end{quote} |
| 1490 |
% but here each \word{page} is a list with the structure |
| 1491 |
% \begin{quote} |
| 1492 |
% \word{page name} \word{key--value list} \word{item list} |
| 1493 |
% \end{quote} |
| 1494 |
% and each \word{item list} in turn is a list of items, each of with |
| 1495 |
% are themselves lists and have the structure |
| 1496 |
% \begin{quote} |
| 1497 |
% \word{key} \word{type} \word{name} \word{help}\regopt |
| 1498 |
% \end{quote} |
| 1499 |
% The return value is a list with the structure |
| 1500 |
% \begin{quote} |
| 1501 |
% \begin{regexp}[\regplus]\word{page name} |
| 1502 |
% \word{key--value list}\end{regexp} |
| 1503 |
% \end{quote} |
| 1504 |
% and in both cases the \word{key--value list} has the format of a |
| 1505 |
% list returned by |array get|, i.e., |
| 1506 |
% \begin{quote} |
| 1507 |
% \begin{regexp}[\regstar]\word{key} \word{value}\end{regexp} |
| 1508 |
% \end{quote} |
| 1509 |
% |
| 1510 |
% Rather than (as with |make|) including the value of an item in its |
| 1511 |
% \word{item} list, that list contains a \word{key} which references |
| 1512 |
% a value stored in the \word{key--value list} of that page. The idea |
| 1513 |
% with this is that the input and output formats for values should be |
| 1514 |
% the same, so that the caller has little overhead in converting from |
| 1515 |
% one data format to another. The \word{key--value list} format is |
| 1516 |
% furthermore flexible in that is completely insensitive to changes |
| 1517 |
% that add, remove, or rearrange items within a page. Extra |
| 1518 |
% key--value pairs in the input are ignored and an empty string is |
| 1519 |
% substituted as value for pairs that are missing. |
| 1520 |
% |
| 1521 |
% The \meta{option}s understood by |make_paged| are |
| 1522 |
% \begin{quote} |
| 1523 |
% |-ok| \word{OK button title}\\ |
| 1524 |
% |-cancel| \word{cancel button title}\\ |
| 1525 |
% |-title| \word{dialog window title}\\ |
| 1526 |
% |-defaultpage| \word{name of default page}\\ |
| 1527 |
% |-addbuttons| \word{button list}\\ |
| 1528 |
% |-width| \word{dialog window width}\\ |
| 1529 |
% |-alpha7pagelimit| \word{maximal number of pages}\\ |
| 1530 |
% |-debug| \word{debug level}\\ |
| 1531 |
% |-changedpages| \word{var-name}\\ |
| 1532 |
% |-changeditems| \word{var-name} |
| 1533 |
% \end{quote} |
| 1534 |
% Those that are common with |make| work exactly the same. The |
| 1535 |
% |-changedpages| option specifies that the caller wants to know on |
| 1536 |
% which pages something was changed. The \word{var-name} is the name |
| 1537 |
% of a variable in the caller's local context which will be set to |
| 1538 |
% the list of (names of) pages where some item value was changed. The |
| 1539 |
% |-changeditems| option is similar, but here the variable will be set |
| 1540 |
% to a list with the structure |
| 1541 |
% \begin{quote} |
| 1542 |
% \begin{regexp}[\regstar]\word{page name} |
| 1543 |
% \word{key list}\end{regexp} |
| 1544 |
% \end{quote} |
| 1545 |
% where the \word{key list}s are lists of the \emph{keys} of items on |
| 1546 |
% that page whose values were changed. |
| 1547 |
% |
| 1548 |
% \begin{tcl} |
| 1549 |
proc dialog::make_paged {args} { |
| 1550 |
% \end{tcl} |
| 1551 |
% |
| 1552 |
% |make_paged| largely has the same local variables as |make|, but |
| 1553 |
% there are some additions. The major arrays are |
| 1554 |
% \begin{description} |
| 1555 |
% \item[\texttt{pageA}] |
| 1556 |
% The index into this array is the name of a page. An entry |
| 1557 |
% contains the list of names of items on that page. |
| 1558 |
% \item[\texttt{typeA}] |
| 1559 |
% The index into this array has the form |
| 1560 |
% \meta{page}|,|\meta{item}, where \meta{page} is the name of a |
| 1561 |
% page and \meta{item} is the name of an item on that page. An |
| 1562 |
% entry contains the type of that item. |
| 1563 |
% \item[\texttt{keyA}] |
| 1564 |
% The index has the same form as in the |typeA| array. An entry |
| 1565 |
% contains the \word{key} for that item. |
| 1566 |
% \item[\texttt{helpA}] |
| 1567 |
% The index has the same form as in the |typeA| array. An entry |
| 1568 |
% contains the help text for that entry, but an item needs not |
| 1569 |
% have an entry in this array (it can be left unset). |
| 1570 |
% \end{description} |
| 1571 |
% There are a couple of additional scalar variables that are of |
| 1572 |
% interest. |
| 1573 |
% \begin{description} |
| 1574 |
% \item[\texttt{retCode}, \texttt{retVal}] |
| 1575 |
% When the |retCode| variable is set, the dialog is logically |
| 1576 |
% closed and the procedure returns. If the variable is set to |0| |
| 1577 |
% then |make| executes a normal return and the returned value will |
| 1578 |
% be the list of item values. If the variable is set to anything |
| 1579 |
% else then that will used for the |-code| option of |return| and |
| 1580 |
% the returned value will be taken from the |retVal| variable, |
| 1581 |
% which must then be initalised. |
| 1582 |
% \item[\texttt{dial}] |
| 1583 |
% This contains the reference string to use with |valGet|, |
| 1584 |
% |valSet|, and friends when accessing the values of items in |
| 1585 |
% the dialog. |
| 1586 |
% \item[\texttt{currentpage}] |
| 1587 |
% This contains the name of the current page in the dialog. |
| 1588 |
% \item[\texttt{delta\_pages}] |
| 1589 |
% This is the list of all pages which have been added to or |
| 1590 |
% deleted from the dialog since it was called. The |add_page| and |
| 1591 |
% |delete_page| procedures both directly access this list. It is |
| 1592 |
% needed to get the information for the |-changedpages| and |
| 1593 |
% |-changeditems| correct. |
| 1594 |
% \item[\texttt{pages}] |
| 1595 |
% This is a list of pages and items to show in the dialog. It is |
| 1596 |
% similar to the result of |array get pageA|, but the order of |
| 1597 |
% pages is as specified in the call and hidden pages are not |
| 1598 |
% included. |
| 1599 |
% \item[\texttt{opts(-addbuttons)}] |
| 1600 |
% This is \word{button list} specified by the caller. Button |
| 1601 |
% scripts can modify this list to change the text on their button. |
| 1602 |
% \item[\texttt{state}] |
| 1603 |
% This is initialized to |0| before the first time the dialog is |
| 1604 |
% shown and then the procedure leaves it alone. Button scripts may |
| 1605 |
% change it to keep track of what ``state'' (mostly: which |
| 1606 |
% items\slash pages are currently hidden) the dialog is in. |
| 1607 |
% \item[\texttt{splitstate}] |
| 1608 |
% This is the dialog splitting state and works as for |
| 1609 |
% |dialog::make|. |
| 1610 |
% \item[\texttt{optionL}] |
| 1611 |
% The list of additional options to pass to |dialog::handle|. |
| 1612 |
% \end{description} |
| 1613 |
% |
| 1614 |
% The first part of |dialog::make_paged| processes the arguments. |
| 1615 |
% \begin{tcl} |
| 1616 |
set opts(-ok) OK |
| 1617 |
set opts(-cancel) Cancel |
| 1618 |
set opts(-title) "" |
| 1619 |
set opts(-width) 400 |
| 1620 |
set opts(-debug) 0 |
| 1621 |
getOpts {-title -defaultpage -ok -cancel -addbuttons -width -debug\ |
| 1622 |
-alpha7pagelimit -changedpages -changeditems} |
| 1623 |
set dial [dialog::create] |
| 1624 |
% \end{tcl} |
| 1625 |
% The page arguments are interpreted by the |add_page| procedure. |
| 1626 |
% Since these pages aren't new in the sense that is relevant for the |
| 1627 |
% |delta_pages| list, that variable is reset afterwards. The |
| 1628 |
% |splitstate| variable is implicitly updated by |add_page|. |
| 1629 |
% \begin{tcl} |
| 1630 |
set pages [list] |
| 1631 |
set delta_pages [list] |
| 1632 |
if {[info exists opts(-alpha7pagelimit)] && [info tclversion]<8.0}\ |
| 1633 |
then { |
| 1634 |
set splitstate below |
| 1635 |
} else { |
| 1636 |
set splitstate off |
| 1637 |
} |
| 1638 |
foreach pagearg $args { |
| 1639 |
eval [list dialog::add_page] $pagearg |
| 1640 |
} |
| 1641 |
set delta_pages [list] |
| 1642 |
if {$splitstate=="page"} then {set splitstate menu} |
| 1643 |
if {[info exists opts(-defaultpage)]} then { |
| 1644 |
set currentpage $opts(-defaultpage) |
| 1645 |
} else { |
| 1646 |
set currentpage [lindex $pages 0] |
| 1647 |
} |
| 1648 |
set optionL [list -width $opts(-width) -title $opts(-title)] |
| 1649 |
set main_buttons [list\ |
| 1650 |
% |
| 1651 |
[list $opts(-ok) "Click here to use the current settings."\ |
| 1652 |
{set retCode 0}\ |
| 1653 |
% |
| 1654 |
$opts(-cancel) "Click here to discard any\ |
| 1655 |
changes you've made to the settings."\ |
| 1656 |
{set retCode 1; set retVal "cancel"}]\ |
| 1657 |
% |
| 1658 |
first right] |
| 1659 |
set view_button [list [list {View dialog page}\ |
| 1660 |
{Click here to see the items on this page.}\ |
| 1661 |
{set splitstate page}]] |
| 1662 |
set back_button [list [list "Back"\ |
| 1663 |
{Click here to go back to the pages menu.}\ |
| 1664 |
{set splitstate menu}] first right] |
| 1665 |
% \end{tcl} |
| 1666 |
% |
| 1667 |
% The second part is the loop which lets the user edit the settings. |
| 1668 |
% \begin{tcl} |
| 1669 |
set state 0 |
| 1670 |
while {![info exists retCode]} { |
| 1671 |
switch -exact -- $splitstate off - below { |
| 1672 |
if {[info exists opts(-addbuttons)]} then { |
| 1673 |
set script [dialog::handle $pages typeA $dial helpA\ |
| 1674 |
currentpage $optionL [list $opts(-addbuttons)]\ |
| 1675 |
$main_buttons] |
| 1676 |
} else { |
| 1677 |
set script [dialog::handle $pages typeA $dial helpA\ |
| 1678 |
currentpage $optionL $main_buttons] |
| 1679 |
} |
| 1680 |
} menu { |
| 1681 |
set altpages [list] |
| 1682 |
set n 1 |
| 1683 |
foreach item $pages { |
| 1684 |
if {$n} then { |
| 1685 |
lappend altpages $item |
| 1686 |
set n 0 |
| 1687 |
} else { |
| 1688 |
lappend altpages {} |
| 1689 |
set n 1 |
| 1690 |
} |
| 1691 |
} |
| 1692 |
set script [dialog::handle $altpages typeA $dial helpA\ |
| 1693 |
currentpage $optionL $view_button $main_buttons] |
| 1694 |
} page { |
| 1695 |
% \end{tcl} |
| 1696 |
% This is a small test to make sure that the value of |currentpage| |
| 1697 |
% is valid. If it isn't then one should return to the |menu| state. |
| 1698 |
% \begin{tcl} |
| 1699 |
if {![info exists pageA($currentpage)]} then { |
| 1700 |
set splitstate menu |
| 1701 |
continue |
| 1702 |
} |
| 1703 |
set altpages [list $currentpage $pageA($currentpage)] |
| 1704 |
if {[info exists opts(-addbuttons)]} then { |
| 1705 |
set script [dialog::handle $altpages typeA $dial helpA\ |
| 1706 |
currentpage $optionL [list $opts(-addbuttons)]\ |
| 1707 |
$back_button] |
| 1708 |
} else { |
| 1709 |
set script [dialog::handle $altpages typeA $dial helpA\ |
| 1710 |
currentpage $optionL $back_button] |
| 1711 |
} |
| 1712 |
} |
| 1713 |
if {[catch $script err]} then { |
| 1714 |
% \end{tcl} |
| 1715 |
% The rest of this loop is simply for gracefully handling errors that |
| 1716 |
% occur when button scripts are evaluated. |
| 1717 |
% \begin{tcl} |
| 1718 |
global errorInfo |
| 1719 |
set errinfo $errorInfo |
| 1720 |
if {$opts(-debug)} then { |
| 1721 |
tclLog "Error in button script '$script'" |
| 1722 |
tclLog $err |
| 1723 |
} |
| 1724 |
dialog::cleanup $dial |
| 1725 |
return -code 1 -errorinfo $errinfo\ |
| 1726 |
"Error '$err' when evaluating button script." |
| 1727 |
} |
| 1728 |
} |
| 1729 |
% \end{tcl} |
| 1730 |
% |
| 1731 |
% The third part is as in |make| responsible for constructing the result |
| 1732 |
% to return (at normal returns). Unlike the case with |make|, the |
| 1733 |
% return value covers only the items currently in |pages|. This |
| 1734 |
% part is also responsible for constructing the lists of changed |
| 1735 |
% pages and items. Two important variables in this are |cS| and |cA|. |
| 1736 |
% |cS| is an array which is used to test whether a certain item has |
| 1737 |
% been changed (via |valChanged|), but the only thing that matters is |
| 1738 |
% whether an entry has been set or not. |cA| is an array indexed by |
| 1739 |
% page name, whereas the entries are lists of keys of items on that |
| 1740 |
% page which have been changed. |
| 1741 |
% \begin{tcl} |
| 1742 |
if {$retCode==0} then { |
| 1743 |
set retVal [list] |
| 1744 |
global dialog::mute_types |
| 1745 |
foreach page $delta_pages { |
| 1746 |
foreach name $pageA($page) { |
| 1747 |
lappend cA($page) $keyA($page,$name) |
| 1748 |
} |
| 1749 |
} |
| 1750 |
foreach item [dialog::changed_items $dial] {set cS($item) ""} |
| 1751 |
newforeach {page items} $pages { |
| 1752 |
set res [list] |
| 1753 |
foreach name $items { |
| 1754 |
set T "$page,$name" |
| 1755 |
if {[lsearch -exact ${dialog::mute_types}\ |
| 1756 |
[lindex $typeA($T) 0]] < 0} then { |
| 1757 |
lappend res $keyA($T) [dialog::valGet $dial $T] |
| 1758 |
if {[info exists cS($T)]} then { |
| 1759 |
lunion cA($page) $keyA($T) |
| 1760 |
} |
| 1761 |
} |
| 1762 |
} |
| 1763 |
lappend retVal $page $res |
| 1764 |
} |
| 1765 |
if {[info exists opts(-changedpages)]} then { |
| 1766 |
upvar 1 $opts(-changedpages) cp |
| 1767 |
set cp [array names cA] |
| 1768 |
} |
| 1769 |
if {[info exists opts(-changeditems)]} then { |
| 1770 |
upvar 1 $opts(-changeditems) ci |
| 1771 |
set ci [array get cA] |
| 1772 |
} |
| 1773 |
} |
| 1774 |
dialog::cleanup $dial |
| 1775 |
return -code $retCode $retVal |
| 1776 |
} |
| 1777 |
% \end{tcl} |
| 1778 |
% \end{proc} |
| 1779 |
% |
| 1780 |
% \begin{proc}{add_page} |
| 1781 |
% The |add_page| procedure can be called from within the |make_paged| |
| 1782 |
% procedure to add a new page to the dialog. The syntax is |
| 1783 |
% \begin{quote} |
| 1784 |
% |dialog::add_page| \word{page name} \word{key--value list} |
| 1785 |
% \word{item list} \word{position}\regopt |
| 1786 |
% \end{quote} |
| 1787 |
% Here the \word{page name}, \word{key--value list}, and \word{item |
| 1788 |
% list} coincide with those parts of a \word{page} argument of |
| 1789 |
% |make_paged|. |
| 1790 |
% |
| 1791 |
% |add_page| works by modifying the arrays |typeA|, |keyA|, |helpA|, |
| 1792 |
% and |pageA|, the lists |pages| and |delta_pages|, and the variable |
| 1793 |
% |splitstate| in the caller's local context. It also uses the value |
| 1794 |
% in the |dial| variable there as an argument to |valSet| and the |
| 1795 |
% |opts| array to access the |-alpha7pagelimit| value. All of these |
| 1796 |
% variables are assumed to function as they do in the |make_paged| |
| 1797 |
% procedure. |
| 1798 |
% |
| 1799 |
% The \word{position} argument can be used to specify where in the |
| 1800 |
% |pages| list that the new page should be inserted. It defaults to |
| 1801 |
% |end|, which puts the new page last. Otherwise the argument should |
| 1802 |
% be numeric: |0| means put first, |1| means put second, |2| means put |
| 1803 |
% third, etc. |
| 1804 |
% |
| 1805 |
% If |splitstate| is |below| and the number of pages equals (or is |
| 1806 |
% greater than) the |-alpha7pagelimit| then the |splitstate| is |
| 1807 |
% changed to |page|. If |splitstate| is |menu| then it is also |
| 1808 |
% changed to |page|. |
| 1809 |
% \begin{tcl} |
| 1810 |
proc dialog::add_page {page keyvalL itemsL {pos end}} { |
| 1811 |
upvar pageA pageA typeA typeA helpA helpA keyA keyA\ |
| 1812 |
dial dial pages pages delta_pages delta_pages\ |
| 1813 |
splitstate splitstate opts opts |
| 1814 |
array set local $keyvalL |
| 1815 |
set pageA($page) [list] |
| 1816 |
lunion delta_pages $page |
| 1817 |
foreach item $itemsL { |
| 1818 |
set key [lindex $item 0] |
| 1819 |
set name [lindex $item 2] |
| 1820 |
set keyA($page,$name) $key |
| 1821 |
if {[info exists local($key)]} then { |
| 1822 |
dialog::valSet $dial $page,$name $local($key) |
| 1823 |
} else { |
| 1824 |
dialog::valSet $dial $page,$name "" |
| 1825 |
} |
| 1826 |
set typeA($page,$name) [lindex $item 1] |
| 1827 |
if {[llength $item]>3} then { |
| 1828 |
set helpA($page,$name) [lindex $item 3] |
| 1829 |
} |
| 1830 |
lappend pageA($page) $name |
| 1831 |
} |
| 1832 |
if {$pos!="end"} then { |
| 1833 |
set pages [linsert $pages [expr {2*$pos}] $page $pageA($page)] |
| 1834 |
} else { |
| 1835 |
lappend pages $page $pageA($page) |
| 1836 |
} |
| 1837 |
if {$splitstate=="menu" || ($splitstate=="below" &&\ |
| 1838 |
[llength $pages]>2*$opts(-alpha7pagelimit))} then { |
| 1839 |
set splitstate page |
| 1840 |
} |
| 1841 |
} |
| 1842 |
% \end{tcl} |
| 1843 |
% \end{proc} |
| 1844 |
% |
| 1845 |
% \begin{proc}{delete_pages} |
| 1846 |
% In one sense, this procedure does the opposite of |add_page|, but |
| 1847 |
% it can be used to achieve different effects as well. Basically it |
| 1848 |
% takes a list of page names and items, in the format for the first |
| 1849 |
% argument of |handle|, and returns the same list with some pages |
| 1850 |
% removed. The syntax is |
| 1851 |
% \begin{quote} |
| 1852 |
% |dialog::delete_pages| \word{pages} \word{delete-list} |
| 1853 |
% \word{deleted-var}\regopt |
| 1854 |
% \end{quote} |
| 1855 |
% where the \word{delete-list} is the list of names of pages to |
| 1856 |
% remove. \word{deleted-var} is, if it is given, the name of a |
| 1857 |
% variable in the caller's local context containing a list of page |
| 1858 |
% names. The deleted pages are then unioned with this list. The most |
| 1859 |
% common value for \word{deleted-var} is |delta_pages|. |
| 1860 |
% |
| 1861 |
% If there is a \word{deleted-var} argument then this procedure might |
| 1862 |
% also modify the |splitstate| variable in the caller's local |
| 1863 |
% context. A value of |page| is changed to |menu| or |below| depending |
| 1864 |
% on how meny pages are returned and the value of |
| 1865 |
% |opts(-alpha7pagelimit)| in the caller's local context. (Both these |
| 1866 |
% variables must exist if |delete_pages| is called with a |
| 1867 |
% \word{deleted-var} argument.) |
| 1868 |
% \begin{tcl} |
| 1869 |
proc dialog::delete_pages {pages deleteL {deletedvar {}}} { |
| 1870 |
set res [list] |
| 1871 |
if {[string length $deletedvar]} then {upvar 1 $deletedvar diffL} |
| 1872 |
newforeach {page items} $pages { |
| 1873 |
if {[lsearch -exact $deleteL $page] == -1} then { |
| 1874 |
lappend res $page $items |
| 1875 |
} else { |
| 1876 |
lunion diffL $page |
| 1877 |
} |
| 1878 |
} |
| 1879 |
if {[string length $deletedvar]} then { |
| 1880 |
upvar splitstate state opts(-alpha7pagelimit) limit |
| 1881 |
switch -exact -- $state page - menu { |
| 1882 |
if {[llength $res]<=2*$limit} then { |
| 1883 |
set state below |
| 1884 |
} else { |
| 1885 |
set state menu |
| 1886 |
} |
| 1887 |
} |
| 1888 |
} |
| 1889 |
return $res |
| 1890 |
} |
| 1891 |
% \end{tcl} |
| 1892 |
% \end{proc} |
| 1893 |
% |
| 1894 |
% |
| 1895 |
% \begin{tcl} |
| 1896 |
} |
| 1897 |
%</dialogspatch&atcl7> |
| 1898 |
% \end{tcl} |
| 1899 |
% \setnamespace{eemenu} |
| 1900 |
% |
| 1901 |
% |
| 1902 |
% \section{Extraction methods} |
| 1903 |
% \label{Sec:Extraction} |
| 1904 |
% |
| 1905 |
% The extraction method is mainly a source of input for an \eemenu\ |
| 1906 |
% command, but it is also responsible for providing some feedback to the |
| 1907 |
% user in the event that an error occurs. This feedback should take the |
| 1908 |
% simple form of positioning the cursor at the beginning of the first |
| 1909 |
% piece of code that could not be evaluated successfully. Extraction |
| 1910 |
% methods are therefore expected to constantly keep track of the |
| 1911 |
% position where the cursor should be put if an error occurs: this is |
| 1912 |
% called the \emph{safe} position. As no other part of an \eemenu\ |
| 1913 |
% cares about positions, these are regarded as internal matters for |
| 1914 |
% the extraction mathod. The feedback from the main executive is |
| 1915 |
% restricted to answers to the simple questions ``Is the current position |
| 1916 |
% safe?'' and ``Did an error occur?'' |
| 1917 |
% |
| 1918 |
% Extractions are begun by a call to the |
| 1919 |
% \describestring[proc][eemenu::\meta{method}]{start}|start| |
| 1920 |
% procedure, which has the syntax |
| 1921 |
% \begin{quote} |
| 1922 |
% |eemenu::|\meta{method}|::start| \word{settings} |
| 1923 |
% \word{window}\regopt\ |
| 1924 |
% \begin{regexp}[\regopt]\word{start} \word{end}\end{regexp} |
| 1925 |
% \end{quote} |
| 1926 |
% The \word{settings} is the |extract_extra| list of the command, and |
| 1927 |
% contain the settings that should be used until the next call to |
| 1928 |
% |start|. This list may contain key--value pairs for details not used |
| 1929 |
% by the current method (but which presumably are used by others), and |
| 1930 |
% it needs not contain key--value pairs for every detail that the |
| 1931 |
% current method uses. Therefore the method should provide defaults |
| 1932 |
% when necessary. |
| 1933 |
% |
| 1934 |
% The \word{window} is the name of the window from which code should be |
| 1935 |
% extracted. If this is omitted then the extraction should default to |
| 1936 |
% using the current window. The \word{start} and \word{end} are |
| 1937 |
% positions of the beginning and end respectively of the interval from |
| 1938 |
% which code should be extracted, but they are normally not used. When |
| 1939 |
% these are omitted then the method may do whatever seems reasonable, |
| 1940 |
% but the following algorith is recommended: |
| 1941 |
% \begin{itemize} |
| 1942 |
% \item If there is a selection in the window, then substitute the |
| 1943 |
% position of its beginning for \word{start} and the position of its |
| 1944 |
% end for \word{end}. |
| 1945 |
% \item Otherwise do the entire window, i.e., let \word{start} be the |
| 1946 |
% |minPos| and \word{end} be the |maxPos|. |
| 1947 |
% \end{itemize} |
| 1948 |
% The main reason that \word{start} and \word{end} at all exist as |
| 1949 |
% arguments is that this simplifies testing and debugging, but it also |
| 1950 |
% enables virtual methods to make their own decisions about from where |
| 1951 |
% the code should be extracted. |
| 1952 |
% |
| 1953 |
% The |start| procedure returns the file name (complete path, no count) |
| 1954 |
% of the source window. This is passed on to the begin procedures of |
| 1955 |
% other methods, but most of them ignore it anyway. If something is |
| 1956 |
% wrong with the arguments supplied to it then |start| terminates with |
| 1957 |
% an error. |
| 1958 |
% |
| 1959 |
% To actually extract a line, the main executive calls the |
| 1960 |
% \describestring[proc][eemenu::\meta{method}]{next}|next| procedure, |
| 1961 |
% which has the syntax |
| 1962 |
% \begin{quote} |
| 1963 |
% |eemenu::|\meta{method}|::next| \word{is safe} |
| 1964 |
% \end{quote} |
| 1965 |
% This procedure returns the next extractable code line, or terminates |
| 1966 |
% with return code 9 if there is no more line. |
| 1967 |
% \changes{v\,0.2}{2002/12/26}{Throwing abort instead of error, since |
| 1968 |
% it otherwise catches too many real errors. (LH)} |
| 1969 |
% The \word{is safe} argument is |1| if the current position should be |
| 1970 |
% considered safe and |0| otherwise. |
| 1971 |
% |
| 1972 |
% Extraction is terminated by a call to the |
| 1973 |
% \describestring[proc][eemenu::\meta{method}]{finish}|finish| |
| 1974 |
% procedure. This has the syntax |
| 1975 |
% \begin{quote} |
| 1976 |
% |eemenu::|\meta{method}|::finish| \word{error?} |
| 1977 |
% \end{quote} |
| 1978 |
% where the \word{error?} argument is |1| if there was an error in |
| 1979 |
% evaluation and |0| otherwise. This procedure does not return any data. |
| 1980 |
% |
| 1981 |
% |
| 1982 |
% \subsection{Some position utilities} |
| 1983 |
% |
| 1984 |
% \textit{\textbf{Note:} The procedures in this subsection were probably |
| 1985 |
% not a good idea to start with, so they are no longer included by |
| 1986 |
% default.} For the historically interested reader, it may be remarked |
| 1987 |
% that the code below predates the addition in \AlphaTcl\,7.6 of |-w| |
| 1988 |
% options to most standard position procedures. |
| 1989 |
% |
| 1990 |
% Extraction procedures should generally not assume that the window from |
| 1991 |
% which code is being extracted is the current window. The reason for |
| 1992 |
% this is that if \Alpha\ is evaulating internally then the extracted |
| 1993 |
% code may bring some other window to front or, more commonly, create a |
| 1994 |
% new window (which will by default go on top of all others). This is |
| 1995 |
% kind of tricky since many of \Alpha's commands for working with |
| 1996 |
% positions implicitly assume that the positions are in the current |
| 1997 |
% window, but it can be delt with by storing positions are a pair |
| 1998 |
% |{|\word{row} \word{column}|}| instead, as the |rowColToPos| command |
| 1999 |
% which converts this to a standard position does accept a window |
| 2000 |
% argument. |
| 2001 |
% |
| 2002 |
% Handling explicitly such positions is however more work that it |
| 2003 |
% should be, so here follows some generic utility procs to deal with |
| 2004 |
% positions specified as lists with the structure |
| 2005 |
% \begin{quote} |
| 2006 |
% \word{window} \word{row} \word{column} \word{standard pos}\regopt |
| 2007 |
% \end{quote} |
| 2008 |
% Here, \word{window} is a full window name (as returned by the |
| 2009 |
% |win::Current| procedure), whereas \word{row} and \word{column} |
| 2010 |
% are integers. The optional \word{standard pos} element is the standard |
| 2011 |
% position (that which should be used in calls to \Alpha\ primitives) if |
| 2012 |
% it has been computed by a call to |rowColToPos|. If it has not been |
| 2013 |
% computed then this element should not be present in the list. |
| 2014 |
% |
| 2015 |
% For \AlphaTk, there isn't much point in a distinction between the |
| 2016 |
% ``standard'' and row--column position formats as standard |
| 2017 |
% positions there are composed from a row and a column anyway. |
| 2018 |
% |
| 2019 |
% These procedures are put in the |
| 2020 |
% \describestring[namespace]{pos}|pos| namespace, as there is nothing |
| 2021 |
% in them that is specific to \eemenu. |
| 2022 |
% \begin{tcl} |
| 2023 |
%<*rowcol> |
| 2024 |
namespace eval pos {} |
| 2025 |
% \end{tcl} |
| 2026 |
% \setnamespace{pos} |
| 2027 |
% |
| 2028 |
% \begin{proc}{incr_row} |
| 2029 |
% \begin{proc}{incr_col} |
| 2030 |
% The |incr_row| and |incr_col| procedures increment the row and |
| 2031 |
% column respectively component of a position list. Their syntaxes are |
| 2032 |
% \begin{quote} |
| 2033 |
% |pos::incr_row| \word{pos-var} \word{row increment}\\ |
| 2034 |
% |pos::incr_col| \word{pos-var} \word{column increment} |
| 2035 |
% \end{quote} |
| 2036 |
% Incrementing the column can not cause the row to be incremented. |
| 2037 |
% Incrementing the row sets the column to |0|. The minimal column |
| 2038 |
% value is |0| and the minimal row value is |1|. There are no |
| 2039 |
% maximums in either. |
| 2040 |
% \begin{tcl} |
| 2041 |
proc pos::incr_row {var diff} { |
| 2042 |
upvar 1 $var V |
| 2043 |
set t [expr {[lindex $V 1] + $diff}] |
| 2044 |
if {$t<1} then { |
| 2045 |
set V [list [lindex $V 0] 1 0] |
| 2046 |
} else { |
| 2047 |
set V [list [lindex $V 0] $t 0] |
| 2048 |
} |
| 2049 |
} |
| 2050 |
proc pos::incr_col {var diff} { |
| 2051 |
upvar 1 $var V |
| 2052 |
set t [expr {[lindex $V 2] + $diff}] |
| 2053 |
set V [lrange $V 0 1] |
| 2054 |
if {$t<0} then {lappend V 0} else {lappend V $t} |
| 2055 |
} |
| 2056 |
% \end{tcl} |
| 2057 |
% \end{proc}\end{proc} |
| 2058 |
% |
| 2059 |
% \begin{proc}{get_standard} |
| 2060 |
% The |get_standard| procedure returns the standard position |
| 2061 |
% corresponding the row--column position stored in a variable. It has |
| 2062 |
% the syntax |
| 2063 |
% \begin{quote} |
| 2064 |
% |pos::get_standard| \word{pos-var} |
| 2065 |
% \end{quote} |
| 2066 |
% \begin{tcl} |
| 2067 |
proc pos::get_standard {var} { |
| 2068 |
upvar 1 $var V |
| 2069 |
if {[llength $V]<4} then { |
| 2070 |
lappend V [eval [list rowColToPos -w] $V] |
| 2071 |
} |
| 2072 |
return [lindex $V 3] |
| 2073 |
} |
| 2074 |
% \end{tcl} |
| 2075 |
% \end{proc} |
| 2076 |
% |
| 2077 |
% \begin{proc}{polyset} |
| 2078 |
% The |polyset| procedure is used to convert a list of standard |
| 2079 |
% positions in a certain window to row--column form and store those |
| 2080 |
% in variables, also given as a list. The syntax is |
| 2081 |
% \begin{quote} |
| 2082 |
% |pos::polyset| \word{window} \word{var-list} \word{pos-list} |
| 2083 |
% \end{quote} |
| 2084 |
% If there are more elements in the \word{var-list} than in the |
| 2085 |
% \word{pos-list} then the remaining elements will not be set. |
| 2086 |
% |
| 2087 |
% The reason this procedure works on lists is that \Alpha\ cannot |
| 2088 |
% (or at least will not) determine the row and column for a position |
| 2089 |
% unless that is in the current window. Therefore this procedure might |
| 2090 |
% have to temporarily bring some other window to front to do its stuff. |
| 2091 |
% \begin{tcl} |
| 2092 |
proc pos::polyset {win varL posL} { |
| 2093 |
if {$win != [win::Current]} then { |
| 2094 |
set top [win::Current] |
| 2095 |
bringToFront $win |
| 2096 |
} |
| 2097 |
set N [llength $varL] |
| 2098 |
if {$N > [llength $posL]} then {set N [llength $posL]} |
| 2099 |
for {set n 0} {$n < $N} {incr n} { |
| 2100 |
upvar 1 [lindex $varL $n] V |
| 2101 |
set V [concat [list $win]\ |
| 2102 |
[posToRowCol [lindex $posL $n]] [lindex $posL $n]] |
| 2103 |
} |
| 2104 |
if {[info exists top]} then {bringToFront $top} |
| 2105 |
} |
| 2106 |
% \end{tcl} |
| 2107 |
% \end{proc} |
| 2108 |
% |
| 2109 |
% \begin{proc}{RC_compare} |
| 2110 |
% The |RC_compare| procedure can be used to compare two row--column |
| 2111 |
% positions. The syntax is |
| 2112 |
% \begin{quote} |
| 2113 |
% |pos::RC_compare| \word{first pos} \word{second pos} |
| 2114 |
% \end{quote} |
| 2115 |
% and the result is as for |string compare|. It is an error if the |
| 2116 |
% \word{window} elements of the two arguments are different. |
| 2117 |
% \begin{tcl} |
| 2118 |
proc pos::RC_compare {a b} { |
| 2119 |
if {"[lindex $a 0]" != "[lindex $b 0]"} then { |
| 2120 |
error "Not the same <window>." |
| 2121 |
} |
| 2122 |
if {[lindex $a 1] < [lindex $b 1]} then { |
| 2123 |
return -1 |
| 2124 |
} elseif {[lindex $a 1] > [lindex $b 1]} then { |
| 2125 |
return 1 |
| 2126 |
} elseif {[lindex $a 2] < [lindex $b 2]} then { |
| 2127 |
return -1 |
| 2128 |
} elseif {[lindex $a 2] > [lindex $b 2]} then { |
| 2129 |
return 1 |
| 2130 |
} else { |
| 2131 |
return 0 |
| 2132 |
} |
| 2133 |
} |
| 2134 |
% \end{tcl} |
| 2135 |
% \end{proc} |
| 2136 |
% |
| 2137 |
% |
| 2138 |
% \begin{proc}[eemenu]{get_extract_positions} |
| 2139 |
% The |get_extract_positions| procedure interprets the three optional |
| 2140 |
% arguments for a |start| procedure and sets two specified variables |
| 2141 |
% in the caller's local context to the row--column positions |
| 2142 |
% corresponding to the beginning and the end respectively of interval |
| 2143 |
% from which code should be extracted. The syntax is |
| 2144 |
% \begin{quote} |
| 2145 |
% |eemenu::get_extract_positions| \word{start-var} \word{end-var} |
| 2146 |
% \word{window}\regopt\ |
| 2147 |
% \begin{regexp}[\regopt]\word{start} \word{end}\end{regexp} |
| 2148 |
% \end{quote} |
| 2149 |
% This procedure returns the complete window name (including count). |
| 2150 |
% \begin{tcl} |
| 2151 |
proc eemenu::get_extract_positions {startvar endvar {win ""}\ |
| 2152 |
{startpos ""} {endpos ""}} { |
| 2153 |
if {![string length $win]} then {set win [win::Current]} |
| 2154 |
if {![string length $startpos]} then { |
| 2155 |
set startpos [getPos -w $win] |
| 2156 |
set endpos [selEnd -w $win] |
| 2157 |
if {[pos::compare $startpos == $endpos]} then { |
| 2158 |
set startpos [minPos] |
| 2159 |
set endpos [maxPos -w $win] |
| 2160 |
} |
| 2161 |
} |
| 2162 |
uplevel 1 [list pos::polyset $win [list $startvar $endvar]\ |
| 2163 |
[list $startpos $endpos]] |
| 2164 |
return $win |
| 2165 |
} |
| 2166 |
% \end{tcl} |
| 2167 |
% \end{proc} |
| 2168 |
% |
| 2169 |
% \begin{proc}[eemenu]{get_text} |
| 2170 |
% The |get_text| procedure is mainly a wrapper around the |getText| |
| 2171 |
% command. The syntax is |
| 2172 |
% \begin{quote} |
| 2173 |
% |eemenu::get_text| \word{start-var} \word{end-var} |
| 2174 |
% \end{quote} |
| 2175 |
% where \word{start-var} and \word{end-var} are names of variables |
| 2176 |
% in the caller's local context of row--column positions. The return |
| 2177 |
% value is the text between those positions. |
| 2178 |
% \begin{tcl} |
| 2179 |
proc eemenu::get_text {startvar endvar} { |
| 2180 |
upvar 1 $startvar S $endvar E |
| 2181 |
if {"[lindex $S 0]" != "[lindex $E 0]"} then { |
| 2182 |
error "Not the same <window>." |
| 2183 |
} |
| 2184 |
getText -w [lindex $S 0] [pos::get_standard S] [pos::get_standard E] |
| 2185 |
} |
| 2186 |
%</rowcol> |
| 2187 |
% \end{tcl} |
| 2188 |
% \end{proc} |
| 2189 |
% |
| 2190 |
% |
| 2191 |
% |
| 2192 |
% |
| 2193 |
% \subsection{Raw extraction} |
| 2194 |
% |
| 2195 |
% \begin{arrayentry}[eemenu]{extract}{raw} |
| 2196 |
% Raw extraction has no details. |
| 2197 |
% \begin{tcl} |
| 2198 |
set eemenu::extract(raw) [list] |
| 2199 |
namespace eval eemenu::raw {} |
| 2200 |
% \end{tcl} |
| 2201 |
% \end{arrayentry} |
| 2202 |
% \setnamespace{eemenu::raw} |
| 2203 |
% |
| 2204 |
% \subsubsection{Row--column based extraction} |
| 2205 |
% |
| 2206 |
% This was my original implementation of raw extraction. Unfortunately |
| 2207 |
% it seems that |rowColToPos| is rather slow in \AlphaEight. Hence |
| 2208 |
% there is an alternative implementation below. |
| 2209 |
% |
| 2210 |
% \begin{proc}{start} |
| 2211 |
% \begin{variable}{cur_pos} |
| 2212 |
% \begin{variable}{safe_pos} |
| 2213 |
% \begin{variable}{end_pos} |
| 2214 |
% As this |start| procedure has no details to deal with, it only |
| 2215 |
% has to initialize the three position variables |cur_pos| (current |
| 2216 |
% position), |safe_pos| (most recent safe position), and |end_pos| |
| 2217 |
% (the end position). |
| 2218 |
% \begin{tcl} |
| 2219 |
%<*rowcol> |
| 2220 |
proc eemenu::raw::start {details args} { |
| 2221 |
eemenu::multiupvar cur_pos safe_pos end_pos |
| 2222 |
set win\ |
| 2223 |
[eval [list eemenu::get_extract_positions cur_pos end_pos] $args] |
| 2224 |
set safe_pos $cur_pos |
| 2225 |
return [win::StripCount $win] |
| 2226 |
} |
| 2227 |
% \end{tcl} |
| 2228 |
% \end{variable}\end{variable}\end{variable}\end{proc} |
| 2229 |
% |
| 2230 |
% |
| 2231 |
% \begin{proc}{next} |
| 2232 |
% The |next| procedure is also as simple as it can possibly be. The |
| 2233 |
% only nontrivial thing about it is that it removes carriage returns |
| 2234 |
% and linefeeds at the end of the text returned by |
| 2235 |
% |eemenu::get_text|. |
| 2236 |
% \begin{tcl} |
| 2237 |
proc eemenu::raw::next {at_safe} { |
| 2238 |
eemenu::multiupvar cur_pos safe_pos end_pos |
| 2239 |
if {[pos::RC_compare $cur_pos $end_pos]>=0} then {return -code 9 "Done"} |
| 2240 |
set this $cur_pos |
| 2241 |
if {$at_safe} then {set safe_pos $this} |
| 2242 |
pos::incr_row cur_pos 1 |
| 2243 |
if {[pos::RC_compare $cur_pos $end_pos]>0} then { |
| 2244 |
set cur_pos $end_pos |
| 2245 |
} |
| 2246 |
string trimright [eemenu::get_text this cur_pos] "\n\r" |
| 2247 |
} |
| 2248 |
% \end{tcl} |
| 2249 |
% \end{proc} |
| 2250 |
% |
| 2251 |
% \begin{proc}{finish} |
| 2252 |
% The |finish| procedure is slightly trickier that it has to be. |
| 2253 |
% Rather than doing a |goto| to the safe position, it does a |select| |
| 2254 |
% followed by a |markHilite|, with the end position as end, so that |
| 2255 |
% the mark will be at the end. |
| 2256 |
% \begin{tcl} |
| 2257 |
proc eemenu::raw::finish {was_error} { |
| 2258 |
if {!$was_error} then {return} |
| 2259 |
eemenu::multiupvar safe_pos end_pos |
| 2260 |
bringToFront [lindex $safe_pos 0] |
| 2261 |
select [pos::get_standard safe_pos] [pos::get_standard end_pos] |
| 2262 |
markHilite |
| 2263 |
} |
| 2264 |
%</rowcol> |
| 2265 |
% \end{tcl} |
| 2266 |
% \end{proc} |
| 2267 |
% |
| 2268 |
% |
| 2269 |
% \subsubsection{Queued extraction} |
| 2270 |
% |
| 2271 |
% This alternative implementation of the \textsf{raw} method is based on |
| 2272 |
% extracting a bit more than one would usually need and store the |
| 2273 |
% surplus in a queue of lines that haven't been extracted yet. |
| 2274 |
% |
| 2275 |
% \begin{variable}{line_queue} |
| 2276 |
% \begin{variable}{window} |
| 2277 |
% \begin{variable}{cur_pos} |
| 2278 |
% \begin{variable}{from_pos} |
| 2279 |
% \begin{variable}{safe_pos} |
| 2280 |
% \begin{variable}{end_pos} |
| 2281 |
% The |window| variable holds the name of the window from which text |
| 2282 |
% is being extracted. |
| 2283 |
% The |line_queue| variable is the text that has been gotten from the |
| 2284 |
% window but not yet been properly extracted, split into lines. The |
| 2285 |
% last line is incomplete and thus text must be added to the queue |
| 2286 |
% whenever it has length less than two. |
| 2287 |
% |
| 2288 |
% The |cur_pos| variable is the standard position of the beginning of |
| 2289 |
% the first line in |line_queue|. The |from_pos| variable is the |
| 2290 |
% first position after the last piece of data in |line_queue|. The |
| 2291 |
% |safe_pos| is the last position reported to be safe and the |end_pos| |
| 2292 |
% is the position at which extraction should stop. |
| 2293 |
% \end{variable}\end{variable}\end{variable}\end{variable}\end{variable} |
| 2294 |
% \end{variable} |
| 2295 |
% |
| 2296 |
% \begin{proc}{start} |
| 2297 |
% As this |start| procedure has no details to deal with, it only |
| 2298 |
% has to initialize the six above variables. |
| 2299 |
% \changes{v\,0.3}{2003/05/28}{Storing the tail of the file name, not |
| 2300 |
% the whole path. This avoids unnecessary file system accesses. (LH) |
| 2301 |
% Cf. bug 919.} |
| 2302 |
% \changes{v\,0.3.1}{2003/07/19}{Using complete paths in \AlphaTk, due |
| 2303 |
% to bug~1026. (LH)} |
| 2304 |
% \begin{tcl} |
| 2305 |
%<*!rowcol> |
| 2306 |
proc eemenu::raw::start {details {win ""} {startpos ""} {endpos ""}} { |
| 2307 |
eemenu::multiupvar line_queue window cur_pos from_pos safe_pos end_pos |
| 2308 |
global alpha::platform |
| 2309 |
if {![string length $win]} then {set win [win::Current]} |
| 2310 |
switch -- ${alpha::platform} alpha { |
| 2311 |
set win_tail [file tail $win] |
| 2312 |
} default { |
| 2313 |
set win_tail $win |
| 2314 |
} |
| 2315 |
if {![string length $startpos]} then { |
| 2316 |
set startpos [getPos -w $win_tail] |
| 2317 |
set endpos [selEnd -w $win_tail] |
| 2318 |
if {[pos::compare $startpos == $endpos]} then { |
| 2319 |
set startpos [minPos] |
| 2320 |
set endpos [maxPos -w $win_tail] |
| 2321 |
} |
| 2322 |
} |
| 2323 |
set line_queue [list ""] |
| 2324 |
set window $win_tail |
| 2325 |
set cur_pos $startpos |
| 2326 |
set from_pos $startpos |
| 2327 |
set safe_pos $startpos |
| 2328 |
set end_pos $endpos |
| 2329 |
return [win::StripCount $win] |
| 2330 |
} |
| 2331 |
% \end{tcl} |
| 2332 |
% \end{proc} |
| 2333 |
% |
| 2334 |
% |
| 2335 |
% \begin{proc}{next} |
| 2336 |
% The |next| procedure first retrieves data from the window (if |
| 2337 |
% necessary) and then it extracts the first line from the queue. Data |
| 2338 |
% beyond the |end_pos| are never read into the queue. |
| 2339 |
% |
| 2340 |
% There are two versions of this procedure to account for the new |
| 2341 |
% addition of a |-w| option to |pos::compare| and |pos::math|. |
| 2342 |
% \changes{v\,0.1.2}{2002/12/26}{Fixed a bug concerning pos::compare, |
| 2343 |
% where string compare syntax was used. (LH, who is sure he has |
| 2344 |
% fixed this bug before.)} |
| 2345 |
% \begin{tcl} |
| 2346 |
%<*atcl7> |
| 2347 |
if {[alpha::package vsatisfies -loose\ |
| 2348 |
[alpha::package versions AlphaTcl] 7.6d2]} then { |
| 2349 |
%</atcl7> |
| 2350 |
proc eemenu::raw::next {at_safe} { |
| 2351 |
eemenu::multiupvar line_queue window cur_pos from_pos safe_pos\ |
| 2352 |
end_pos |
| 2353 |
if {[llength $line_queue] < 2} then { |
| 2354 |
if {[pos::compare -w $window $cur_pos >= $end_pos]} then { |
| 2355 |
return -code 9 "Done" |
| 2356 |
} |
| 2357 |
set next_pos [pos::math -w $window $from_pos + 1024] |
| 2358 |
if {[pos::compare -w $window $next_pos >= $end_pos]} then { |
| 2359 |
set next_pos $end_pos |
| 2360 |
} |
| 2361 |
set text [lindex $line_queue end] |
| 2362 |
append text [getText -w $window $from_pos $next_pos] |
| 2363 |
set line_queue [split $text "\n\r"] |
| 2364 |
set from_pos $next_pos |
| 2365 |
} |
| 2366 |
if {$at_safe} then {set safe_pos $cur_pos} |
| 2367 |
set line [lindex $line_queue 0] |
| 2368 |
set line_queue [lreplace $line_queue 0 0] |
| 2369 |
set cur_pos\ |
| 2370 |
[pos::math -w $window $cur_pos + [expr {[string length $line]+1}]] |
| 2371 |
set line |
| 2372 |
} |
| 2373 |
%<*atcl7> |
| 2374 |
} else { |
| 2375 |
proc eemenu::raw::next {at_safe} { |
| 2376 |
eemenu::multiupvar line_queue window cur_pos from_pos safe_pos end_pos |
| 2377 |
if {[llength $line_queue] < 2} then { |
| 2378 |
if {[pos::compare $cur_pos >= $end_pos]} then { |
| 2379 |
return -code 9 "Done" |
| 2380 |
} |
| 2381 |
set next_pos [pos::math $from_pos + 1024] |
| 2382 |
if {[pos::compare $next_pos >= $end_pos]} then { |
| 2383 |
set next_pos $end_pos |
| 2384 |
} |
| 2385 |
set text [lindex $line_queue end] |
| 2386 |
append text [getText -w $window $from_pos $next_pos] |
| 2387 |
set line_queue [split $text "\n\r"] |
| 2388 |
set from_pos $next_pos |
| 2389 |
} |
| 2390 |
if {$at_safe} then {set safe_pos $cur_pos} |
| 2391 |
set line [lindex $line_queue 0] |
| 2392 |
set line_queue [lreplace $line_queue 0 0] |
| 2393 |
set cur_pos [pos::math $cur_pos + [expr {[string length $line]+1}]] |
| 2394 |
set line |
| 2395 |
} |
| 2396 |
} |
| 2397 |
%</atcl7> |
| 2398 |
% \end{tcl} |
| 2399 |
% \end{proc} |
| 2400 |
% |
| 2401 |
% \begin{proc}{finish} |
| 2402 |
% This |finish| procedure clears the |line_queue|. It should usually |
| 2403 |
% be empty already, but better safe than sorry! |
| 2404 |
% \begin{tcl} |
| 2405 |
proc eemenu::raw::finish {was_error} { |
| 2406 |
eemenu::multiupvar line_queue window safe_pos end_pos |
| 2407 |
set line_queue [list] |
| 2408 |
if {!$was_error} then {return} |
| 2409 |
bringToFront $window |
| 2410 |
select $safe_pos $end_pos |
| 2411 |
markHilite |
| 2412 |
} |
| 2413 |
%</!rowcol> |
| 2414 |
% \end{tcl} |
| 2415 |
% \end{proc} |
| 2416 |
% |
| 2417 |
% |
| 2418 |
% \subsection{Regexp extraction} |
| 2419 |
% |
| 2420 |
% Regular expression extraction adds two features to what the raw |
| 2421 |
% extraction does. One is the filter---only lines meeting a certain |
| 2422 |
% condition are extracted, the others are skipped---and the other is the |
| 2423 |
% substitution---each line returned is first fed through a |regsub|. |
| 2424 |
% It would of course be possible to implement this from scratch, but it |
| 2425 |
% is more instructive (and slightly shorter) to base it on the |raw| |
| 2426 |
% method. |
| 2427 |
% |
| 2428 |
% \begin{arrayentry}[eemenu]{extract}{regexp} |
| 2429 |
% Regular expression extraction has four detail settings. |
| 2430 |
% \begin{tcl} |
| 2431 |
set eemenu::extract(regexp) [list\ |
| 2432 |
% \end{tcl} |
| 2433 |
% The first |
| 2434 |
% two are used in a ``filter'' that selects which lines will be |
| 2435 |
% extracted: |
| 2436 |
% \begin{details}{Extraction} |
| 2437 |
% \detailitem{filter_mode} |
| 2438 |
% This is the mode of operation for the filter. There are three |
| 2439 |
% possible values: |off| (no filtering, all lines are extracted), |
| 2440 |
% |grep| (only lines matching the |filterRE| regular expression |
| 2441 |
% are extracted), and |anti-grep| (only lines \emph{not} matching |
| 2442 |
% the |filterRE| regular expression are extracted). |
| 2443 |
% \begin{tcl} |
| 2444 |
[eemenu::define_detail Extract "Filter mode"\ |
| 2445 |
filter_mode [list menu [list off grep anti-grep]] off]\ |
| 2446 |
% \end{tcl} |
| 2447 |
% \detailitem{filterRE} |
| 2448 |
% This is the regular expression for the filter |
| 2449 |
% \begin{tcl} |
| 2450 |
[eemenu::define_detail Extract "Filter regular expression"\ |
| 2451 |
filterRE var]\ |
| 2452 |
% \end{tcl} |
| 2453 |
% \end{details} |
| 2454 |
% The last two are used in a straightforward |regsub| that is applied |
| 2455 |
% to each extracted line before it is returned to the main executive. |
| 2456 |
% \begin{details}{Extraction} |
| 2457 |
% \detailitem{searchRE} |
| 2458 |
% This is the regular expression searched for in the line. |
| 2459 |
% \begin{tcl} |
| 2460 |
[eemenu::define_detail Extract "Search (regexp):" searchRE var]\ |
| 2461 |
% \end{tcl} |
| 2462 |
% \detailitem{replaceRE} |
| 2463 |
% This is the regular expression for the replacement. |
| 2464 |
% \begin{tcl} |
| 2465 |
[eemenu::define_detail Extract "Replace (regexp):" replaceRE var]] |
| 2466 |
% \end{tcl} |
| 2467 |
% \end{details} |
| 2468 |
% \end{arrayentry} |
| 2469 |
% \begin{tcl} |
| 2470 |
namespace eval eemenu::regexp {} |
| 2471 |
% \end{tcl} |
| 2472 |
% \setnamespace{eemenu::regexp} |
| 2473 |
% |
| 2474 |
% \begin{proc}{start} |
| 2475 |
% \begin{arrayvar}{detA} |
| 2476 |
% This |start| procedure stores its details in the |D| array and calls |
| 2477 |
% the |evalmemu::raw::start| procedure to handle everything else. |
| 2478 |
% Note how it provides defaults for the detail settings it |
| 2479 |
% unconditionally uses, in case these are not present in the |
| 2480 |
% \word{details}. |
| 2481 |
% \begin{tcl} |
| 2482 |
proc eemenu::regexp::start {details args} { |
| 2483 |
global eemenu::regexp::detA |
| 2484 |
array set eemenu::regexp::detA\ |
| 2485 |
{filter_mode off searchRE {} replaceRE {}} |
| 2486 |
array set eemenu::regexp::detA $details |
| 2487 |
eval [list eemenu::raw::start $details] $args |
| 2488 |
} |
| 2489 |
% \end{tcl} |
| 2490 |
% \end{arrayvar}\end{proc} |
| 2491 |
% |
| 2492 |
% \begin{proc}{next} |
| 2493 |
% The |next| procedure starts with a loop that continues until it |
| 2494 |
% finds a line that passes the filter. |
| 2495 |
% \begin{tcl} |
| 2496 |
proc eemenu::regexp::next {at_safe} { |
| 2497 |
upvar #0 eemenu::regexp::detA D |
| 2498 |
while {1} { |
| 2499 |
set line [eemenu::raw::next $at_safe] |
| 2500 |
switch -- $D(filter_mode) { |
| 2501 |
off {break} |
| 2502 |
grep {if {[regexp -- $D(filterRE) $line]} then {break}} |
| 2503 |
anti-grep { |
| 2504 |
if {![regexp -- $D(filterRE) $line]} then {break} |
| 2505 |
} |
| 2506 |
} |
| 2507 |
} |
| 2508 |
% \end{tcl} |
| 2509 |
% Then it applies the |regsub| to the line. |
| 2510 |
% \begin{tcl} |
| 2511 |
regsub -all -- $D(searchRE) $line $D(replaceRE) line |
| 2512 |
return $line |
| 2513 |
} |
| 2514 |
% \end{tcl} |
| 2515 |
% \end{proc} |
| 2516 |
% |
| 2517 |
% \begin{proc}{finish} |
| 2518 |
% The |finish| procedure simply calls its equivalent for the |raw| |
| 2519 |
% method. |
| 2520 |
% \begin{tcl} |
| 2521 |
proc eemenu::regexp::finish {err} {eemenu::raw::finish $err} |
| 2522 |
% \end{tcl} |
| 2523 |
% \end{proc} |
| 2524 |
% |
| 2525 |
% |
| 2526 |
% |
| 2527 |
% \subsection{Docstrip extraction} |
| 2528 |
% |
| 2529 |
% Docstrip extraction is a descendant of the extraction mechanisms from |
| 2530 |
% the \textsf{dtxload} package. |
| 2531 |
% |
| 2532 |
% |
| 2533 |
% \begin{arrayentry}[eemenu]{extract}{docstrip} |
| 2534 |
% There are three detail settings for |docstrip| extraction. |
| 2535 |
% \begin{tcl} |
| 2536 |
set eemenu::extract(docstrip) [list\ |
| 2537 |
% \end{tcl} |
| 2538 |
% \begin{details}{Extraction} |
| 2539 |
% \detailitem{filePatL} |
| 2540 |
% This is a list of file patterns that the file name is tested |
| 2541 |
% against using |string match|. If none of them fits then |
| 2542 |
% extraction is stopped before is begins. |
| 2543 |
% \begin{tcl} |
| 2544 |
[eemenu::define_detail Extract "File patterns" filePatL var\ |
| 2545 |
"*.dtx" "List of glob-style file patterns the window must match"]\ |
| 2546 |
% \end{tcl} |
| 2547 |
% \detailitem{lookAtEnvs} |
| 2548 |
% If this is checked then extraction will be further conditioned |
| 2549 |
% by that the code line is in one of the environements listed in |
| 2550 |
% the next setting. I find this very convenient, since I often |
| 2551 |
% forget to comment out some lines here and there in the file. |
| 2552 |
% \begin{tcl} |
| 2553 |
[eemenu::define_detail Extract "Filter by environments"\ |
| 2554 |
lookAtEnvs flag 0]\ |
| 2555 |
% \end{tcl} |
| 2556 |
% \detailitem{sourceEnvsL} |
| 2557 |
% The list of environments from which code may be extracted. |
| 2558 |
% \begin{tcl} |
| 2559 |
[eemenu::define_detail Extract "Source environments"\ |
| 2560 |
sourceEnvsL var {tcl tcl*}]] |
| 2561 |
% \end{tcl} |
| 2562 |
% \end{details} |
| 2563 |
% \end{arrayentry} |
| 2564 |
% \begin{tcl} |
| 2565 |
namespace eval eemenu::docstrip {} |
| 2566 |
% \end{tcl} |
| 2567 |
% \setnamespace{eemenu::docstrip} |
| 2568 |
% |
| 2569 |
% \begin{variable}{cur_pos} |
| 2570 |
% \begin{variable}{safe_pos} |
| 2571 |
% \begin{variable}{end_pos} |
| 2572 |
% The |cur_pos|, |safe_pos|, and |end_pos| variables are as for the |
| 2573 |
% |raw| mathod. A special case is however that |safe_pos| will never |
| 2574 |
% be inside a verbatim section, even if it is safe there, since the |
| 2575 |
% extraction wouldn't remember that is was inside a verbatim section |
| 2576 |
% if it was restarted. Therefore the \word{is safe} argument to |next| |
| 2577 |
% will be ignored in verbatim sections. |
| 2578 |
% |
| 2579 |
% These variables are only used by the \Module{rowcol} variant. |
| 2580 |
% \end{variable}\end{variable}\end{variable} |
| 2581 |
% |
| 2582 |
% \begin{variable}{module_included} |
| 2583 |
% \begin{variable}{in_code_env} |
| 2584 |
% \begin{variable}{in_verbatim} |
| 2585 |
% The |module_included| variable keeps track of whether the current |
| 2586 |
% position is in an included module. It is |1| if the current |
| 2587 |
% position should be included and |0| if it shouldn't. |
| 2588 |
% The |in_code_env| variable is used for keeping track of the markup |
| 2589 |
% context of the currently considered line in the file when the |
| 2590 |
% |lookAtEnvs| setting is on. |in_code_env| is set to |1| when a |
| 2591 |
% |\begin{|\meta{env}|}| for an \meta{env} in the |sourceEnvsL| is |
| 2592 |
% scanned, and set to |0| when an |\end{|\meta{env}|}| is scanned. |
| 2593 |
% The |in_verbatim| variable is |1| when the current position is in |
| 2594 |
% a \textsf{docstrip} verbatim module and |0| (which is the normal |
| 2595 |
% case) otherwise. |
| 2596 |
% \end{variable}\end{variable}\end{variable} |
| 2597 |
% |
| 2598 |
% \begin{variable}{module_stack} |
| 2599 |
% \begin{variable}{next_module_idx} |
| 2600 |
% The |module_stack| variable is keeps track of how modules |
| 2601 |
% are nested around the currently considered line. The variable is a |
| 2602 |
% stack implemented as a list in which the last element corresponds to |
| 2603 |
% the innermost module. Each element in this list is itself a list |
| 2604 |
% with the structure |
| 2605 |
% \begin{quote} |
| 2606 |
% \word{expression} \word{start pos.} \word{previous}\regopt |
| 2607 |
% \end{quote} |
| 2608 |
% The \word{expression} is the guard expression, as a string. The |
| 2609 |
% \word{start pos.} is the (row--column) position in the file where |
| 2610 |
% the module started. |
| 2611 |
% Finally, the \word{previous} is a boolean value which |
| 2612 |
% records the inclusion status (value of |module_included|) |
| 2613 |
% that was in force before the module was entered. |
| 2614 |
% |
| 2615 |
% The |next_module_idx| variable holds the index in the |
| 2616 |
% |module_stack| list of the next module whose expression has not yet |
| 2617 |
% been evaluated; it is equal to |llength ${module_stack}| if all |
| 2618 |
% module expressions have been evaluated. Those elements in the |
| 2619 |
% |module_stack| list which have index $\geq$ |next_module_idx| do |
| 2620 |
% not have a \word{previous} element. |
| 2621 |
% \end{variable}\end{variable} |
| 2622 |
% |
| 2623 |
% |
| 2624 |
% \begin{proc}{start} |
| 2625 |
% The |docstrip| extraction |start| procedure is by far the most |
| 2626 |
% complicated, due to the many mechanisms it must initialize. |
| 2627 |
% \begin{tcl} |
| 2628 |
proc eemenu::docstrip::start {details args} { |
| 2629 |
eemenu::multiupvar detA module_included module_stack\ |
| 2630 |
next_module_idx in_code_env in_verbatim |
| 2631 |
% \end{tcl} |
| 2632 |
% First there are the position variables |
| 2633 |
% \begin{tcl} |
| 2634 |
%<*rowcol> |
| 2635 |
eemenu::multiupvar cur_pos safe_pos end_pos |
| 2636 |
set win [win::StripCount\ |
| 2637 |
[eval [list eemenu::get_extract_positions cur_pos end_pos] $args]] |
| 2638 |
set safe_pos $cur_pos |
| 2639 |
%</rowcol> |
| 2640 |
%<*!rowcol> |
| 2641 |
set win [eval [list eemenu::raw::start $details] $args] |
| 2642 |
%</!rowcol> |
| 2643 |
% \end{tcl} |
| 2644 |
% and secondly the setting details |
| 2645 |
% \begin{tcl} |
| 2646 |
array set detA {filePatL *.dtx lookAtEnvs 0} |
| 2647 |
array set detA $details |
| 2648 |
% \end{tcl} |
| 2649 |
% Then the method must check whether the detail setting permit |
| 2650 |
% extracting from this window. If not, the procedure raises an error |
| 2651 |
% (which isn't caught by |eemenu::main|). |
| 2652 |
% \begin{tcl} |
| 2653 |
set ok 0 |
| 2654 |
foreach pat $detA(filePatL) { |
| 2655 |
if {[string match $pat $win]} then {set ok 1; break} |
| 2656 |
} |
| 2657 |
if {!$ok} then { |
| 2658 |
status::msg "Can't extract from that window. Must be\ |
| 2659 |
[join $detA(filePatL) " or "]." |
| 2660 |
return -code 9 "Bad window name" |
| 2661 |
} |
| 2662 |
% \end{tcl} |
| 2663 |
% Now that it has been established that extraction will take place, |
| 2664 |
% the various variables defining the ``state of \textsf{dostrip}'' |
| 2665 |
% must be initialised. Four of them have standard values at start and |
| 2666 |
% present no problem. |
| 2667 |
% \begin{tcl} |
| 2668 |
set module_included 1 |
| 2669 |
set in_verbatim 0 |
| 2670 |
set module_stack [list] |
| 2671 |
set next_module_idx 0 |
| 2672 |
% \end{tcl} |
| 2673 |
% The |in_code_env| variable is however another matter, as the |
| 2674 |
% reasonable value for it depends very much on what characters follow |
| 2675 |
% the start position. The special value |-1| for |in_code_env| means |
| 2676 |
% ``change to |0| or |1| as appropriate when you get the first line''. |
| 2677 |
% \begin{tcl} |
| 2678 |
if {!$detA(lookAtEnvs)} then { |
| 2679 |
set in_code_env 1 |
| 2680 |
} else { |
| 2681 |
%<*rowcol> |
| 2682 |
set t_pos $cur_pos |
| 2683 |
pos::incr_col t_pos 2 |
| 2684 |
switch -regexp -- [eemenu::get_text cur_pos t_pos] { |
| 2685 |
^%< {set in_code_env 1} |
| 2686 |
^% {set in_code_env 0} |
| 2687 |
default {set in_code_env 1} |
| 2688 |
} |
| 2689 |
%</rowcol> |
| 2690 |
%<!rowcol> set in_code_env -1 |
| 2691 |
set detA(envsRE) {\\(begin|end) *\{(} |
| 2692 |
foreach env $detA(sourceEnvsL) { |
| 2693 |
append detA(envsRE) [quote::Regfind $env] "|" |
| 2694 |
} |
| 2695 |
append detA(envsRE) ")\}(.*)\$" |
| 2696 |
} |
| 2697 |
return $win |
| 2698 |
} |
| 2699 |
% \end{tcl} |
| 2700 |
% \end{proc} |
| 2701 |
% |
| 2702 |
% \begin{arrayentry}{detA}{envsRE} |
| 2703 |
% The |envsRE| entry in the |detA| array is used for storing the |
| 2704 |
% regular expression that is used when searching for code environment |
| 2705 |
% markup in comment lines. |
| 2706 |
% \end{arrayentry} |
| 2707 |
% |
| 2708 |
% Next comes a couple of utility procs that are called from the |next| |
| 2709 |
% procedure. |
| 2710 |
% |
| 2711 |
% \begin{arrayvar}{known}[expression] |
| 2712 |
% The |known| array records the values of all known expressions, |
| 2713 |
% i.e., those expressions about whose values the user has been |
| 2714 |
% inquired. The entries are either |0| (for ``don't include'') or |
| 2715 |
% |1| (for ``include''). Note that this array is not initialised by |
| 2716 |
% the |start| procedure---instead is cleared by the |finish| |
| 2717 |
% procedure if no error occurred. |
| 2718 |
% \end{arrayvar} |
| 2719 |
% |
| 2720 |
% \begin{proc}{eval_guard} |
| 2721 |
% The |eval_guard| procedure takes the string that is a guard |
| 2722 |
% expression as argument. It returns |1| if the expression evaluates |
| 2723 |
% to true and |0| if it evaluates to false. |
| 2724 |
% |
| 2725 |
% If the expression has an entry in the |known| array then the |
| 2726 |
% |eval_guard| procedure returns that value, and if it does not the |
| 2727 |
% user is inquired for the value. |
| 2728 |
% \begin{tcl} |
| 2729 |
proc eemenu::docstrip::eval_guard {e} { |
| 2730 |
global eemenu::docstrip::known |
| 2731 |
if {![info exists eemenu::docstrip::known($e)]} then { |
| 2732 |
set eemenu::docstrip::known($e)\ |
| 2733 |
[dialog::yesno "Should <$e> modules be included?"] |
| 2734 |
} |
| 2735 |
set eemenu::docstrip::known($e) |
| 2736 |
} |
| 2737 |
% \end{tcl} |
| 2738 |
% \end{proc} |
| 2739 |
% |
| 2740 |
% |
| 2741 |
% \begin{proc}{push_module} |
| 2742 |
% The |push_module| procedure pushes a block module onto the |
| 2743 |
% module stack, but it does not modify the value of |
| 2744 |
% |module_included|. The syntax is |
| 2745 |
% \begin{quote} |
| 2746 |
% |eemenu::docstrip::push_module| \word{expression} \word{position} |
| 2747 |
% \end{quote} |
| 2748 |
% where \word{expression} is the expression string and |
| 2749 |
% \word{position} is the position (row--column or standard, depending |
| 2750 |
% on which kind of positions are being used) where the guard begins. |
| 2751 |
% \begin{tcl} |
| 2752 |
proc eemenu::docstrip::push_module {e p} { |
| 2753 |
global eemenu::docstrip::module_stack |
| 2754 |
lappend eemenu::docstrip::module_stack [list $e $p] |
| 2755 |
} |
| 2756 |
% \end{tcl} |
| 2757 |
% \end{proc} |
| 2758 |
% |
| 2759 |
% \begin{proc}{pop_module} |
| 2760 |
% The |pop_module| procedure pops a block module off the module |
| 2761 |
% stack and checks that the modules are properly nested. Its |
| 2762 |
% syntax is |
| 2763 |
% \begin{quote} |
| 2764 |
% |eemenu::docstrip::pop_module| \word{expression} \word{position} |
| 2765 |
% \end{quote} |
| 2766 |
% where \word{expression} is the expression string of the module to |
| 2767 |
% pop and \word{position} is the position (row--column or standard, |
| 2768 |
% depending on which kind of positions are being used) where the |
| 2769 |
% end of module guard begins. |
| 2770 |
% |
| 2771 |
% If the module nesting is incorrect then the user is presented with |
| 2772 |
% a dialog with buttons for pushing the positions of the incorrect |
| 2773 |
% modules. It is not an error if the module stack is empty, since it |
| 2774 |
% is perfectly reasonable that the beginning of the code to evaluate |
| 2775 |
% is in the middle of a module. |
| 2776 |
% |
| 2777 |
% \changes{ \textsf{dtxload} v\,1.11}{2001/05/11}{Corrected ugly bug |
| 2778 |
% which messed up the value of \texttt{next\_module\_idx}. (LH)} |
| 2779 |
% \begin{tcl} |
| 2780 |
proc eemenu::docstrip::pop_module {e p} { |
| 2781 |
eemenu::multiupvar module_stack module_included next_module_idx |
| 2782 |
set len [llength $module_stack] |
| 2783 |
if {$len==0} then {return} |
| 2784 |
set L [lindex $module_stack [expr {$len-1}]] |
| 2785 |
if {[lindex $L 0] != $e} then { |
| 2786 |
switch [buttonAlert "Module nesting error: <*[lindex $L 0]>\ |
| 2787 |
module ended by </$e>. For which guards should the positions\ |
| 2788 |
be pushed?" None Start End Both]\ |
| 2789 |
{ |
| 2790 |
Start {eemenu::docstrip::push_bookmarks [lindex $L 1]} |
| 2791 |
End {eemenu::docstrip::push_bookmarks $p} |
| 2792 |
Both {eemenu::docstrip::push_bookmarks [lindex $L 1] $p} |
| 2793 |
} |
| 2794 |
} |
| 2795 |
set module_stack [lreplace $module_stack end end] |
| 2796 |
if {$len<=$next_module_idx} then { |
| 2797 |
set next_module_idx [llength $module_stack] |
| 2798 |
} |
| 2799 |
if {[llength $L]>2} then { |
| 2800 |
set module_included [lindex $L 2] |
| 2801 |
} |
| 2802 |
} |
| 2803 |
% \end{tcl} |
| 2804 |
% \end{proc} |
| 2805 |
% |
| 2806 |
% \begin{proc}{push_bookmarks} |
| 2807 |
% The |push_bookmarks| procedure pushes one or several positions |
| 2808 |
% (row--column or standard, depending on which kind of positions are |
| 2809 |
% being used) onto the bookmarks stack. The arguments are the |
| 2810 |
% positions to push. |
| 2811 |
% \changes{v\,0.3}{2003/05/28}{Changed some \texttt{win::Current} to |
| 2812 |
% \texttt{win::CurrentTail}. This avoids unnecessary file system |
| 2813 |
% accesses. (LH) Cf. bug 919.} |
| 2814 |
% \begin{tcl} |
| 2815 |
proc eemenu::docstrip::push_bookmarks {args} { |
| 2816 |
global markStack markName |
| 2817 |
%<!rowcol> upvar #0 eemenu::raw::window win |
| 2818 |
set topWin [win::CurrentTail] |
| 2819 |
foreach pos $args { |
| 2820 |
set name mark$markName |
| 2821 |
incr markName |
| 2822 |
%<*rowcol> |
| 2823 |
set win [lindex $pos 0] |
| 2824 |
if {"[win::CurrentTail]" != "$win"} then {bringToFront $win} |
| 2825 |
createTMark $name [pos::get_standard pos] |
| 2826 |
set fileName [win::Current] |
| 2827 |
set markStack [linsert $markStack 0\ |
| 2828 |
[list $fileName $name [pos::get_standard pos]]] |
| 2829 |
%</rowcol> |
| 2830 |
%<*!rowcol> |
| 2831 |
if {[string compare [win::CurrentTail] $win]}\ |
| 2832 |
then {bringToFront $win} |
| 2833 |
createTMark $name $pos |
| 2834 |
set fileName [win::Current] |
| 2835 |
set markStack [linsert $markStack 0 [list $fileName $name $pos]] |
| 2836 |
%</!rowcol> |
| 2837 |
} |
| 2838 |
if {[string compare [win::CurrentTail] $topWin]}\ |
| 2839 |
then {bringToFront $topWin} |
| 2840 |
} |
| 2841 |
% \end{tcl} |
| 2842 |
% \end{proc} |
| 2843 |
% |
| 2844 |
% \begin{proc}{update_included} |
| 2845 |
% Simply pushing a module onto the module stack does not update the |
| 2846 |
% |module_included| variable; that is instead done by the |
| 2847 |
% |update_included| procedure, which should be called right before the |
| 2848 |
% value of |module_included| is used. The reason for this arrangement |
| 2849 |
% is that it avoids evaluating guard expressions whose values do not |
| 2850 |
% matter. |
| 2851 |
% |
| 2852 |
% |update_included| has no arguments. |
| 2853 |
% \begin{tcl} |
| 2854 |
proc eemenu::docstrip::update_included {} { |
| 2855 |
eemenu::multiupvar module_stack module_included next_module_idx |
| 2856 |
while {$module_included && $next_module_idx<[llength $module_stack]} { |
| 2857 |
set L [lindex $module_stack $next_module_idx] |
| 2858 |
lappend L $module_included |
| 2859 |
set module_stack\ |
| 2860 |
[lreplace $module_stack $next_module_idx $next_module_idx $L] |
| 2861 |
incr next_module_idx |
| 2862 |
set module_included [eemenu::docstrip::eval_guard [lindex $L 0]] |
| 2863 |
} |
| 2864 |
} |
| 2865 |
% \end{tcl} |
| 2866 |
% \end{proc} |
| 2867 |
% |
| 2868 |
% \begin{variable}{end_verb_line} |
| 2869 |
% The |end_verb_line| variable stores the line which terminates |
| 2870 |
% verbatim mode. It is only initialised when verbatim mode is begun. |
| 2871 |
% \end{variable} |
| 2872 |
% |
| 2873 |
% \begin{proc}{next} |
| 2874 |
% The overall structure of the |next| procedure is that of an endless |
| 2875 |
% loop, from which the code |break|s out when it has found an |
| 2876 |
% extractable line. Should this loop run into the |end_pos| it |
| 2877 |
% terminates instead with a |return -code 9|. The local variable |
| 2878 |
% |next_pos| stores the position of the beginning of the next line. |
| 2879 |
% \begin{tcl} |
| 2880 |
proc eemenu::docstrip::next {is_safe} { |
| 2881 |
eemenu::multiupvar detA module_included in_code_env\ |
| 2882 |
in_verbatim module_stack next_module_idx end_verb_line |
| 2883 |
%<*rowcol> |
| 2884 |
eemenu::multiupvar cur_pos safe_pos end_pos |
| 2885 |
set next_pos $cur_pos |
| 2886 |
%</rowcol> |
| 2887 |
%<!rowcol> upvar #0 eemenu::raw::cur_pos raw_cur_pos |
| 2888 |
while {1} { |
| 2889 |
%<*rowcol> |
| 2890 |
pos::incr_row next_pos 1 |
| 2891 |
if {[pos::RC_compare $next_pos $end_pos]>0} then { |
| 2892 |
set next_pos $end_pos |
| 2893 |
} |
| 2894 |
if {[pos::RC_compare $cur_pos $next_pos]>=0} then { |
| 2895 |
return -code 9 "Done" |
| 2896 |
} |
| 2897 |
% \end{tcl} |
| 2898 |
% No matter what state the extraction process is in, it will need to |
| 2899 |
% look at the current line, so it is extracted and put in the |line| |
| 2900 |
% variable. Spaces at end of the line are ignored for compatibility |
| 2901 |
% with the \TeX\ \package{docstrip} (\TeX\ throws away spaces at the |
| 2902 |
% end of a line as part of the reading process, so \package{docstrip} |
| 2903 |
% cannot see them). |
| 2904 |
% \begin{tcl} |
| 2905 |
set line [string trimright [eemenu::get_text cur_pos next_pos]\ |
| 2906 |
"\r\n "] |
| 2907 |
%</rowcol> |
| 2908 |
% \end{tcl} |
| 2909 |
% In the standard positions implementation, getting text from the |
| 2910 |
% window is instead done by calling |eemenu::raw::next|. The position |
| 2911 |
% at the beginning of the line (the value of |eemenu::raw::cur_pos| |
| 2912 |
% before the call to |eemenu::raw::next|) is saved since it might be |
| 2913 |
% needed for making bookmarks later. |
| 2914 |
% \begin{tcl} |
| 2915 |
%<*!rowcol> |
| 2916 |
set cur_pos $raw_cur_pos |
| 2917 |
set line [eemenu::raw::next [expr {$is_safe && !$in_verbatim}]] |
| 2918 |
set line [string trimright $line "\r\n "] |
| 2919 |
if {$in_code_env<0} then { |
| 2920 |
switch -glob -- $line { |
| 2921 |
%<* {set in_code_env 1} |
| 2922 |
%* {set in_code_env 0} |
| 2923 |
default {set in_code_env 1} |
| 2924 |
} |
| 2925 |
} |
| 2926 |
%</!rowcol> |
| 2927 |
% \end{tcl} |
| 2928 |
% Verbatim mode is pretty simple. Either a line is an extractable |
| 2929 |
% code line or it is the end of verbatim mode guard. |
| 2930 |
% \begin{tcl} |
| 2931 |
if {$in_verbatim} then { |
| 2932 |
if {![string compare $line $end_verb_line]} then { |
| 2933 |
set in_verbatim 0 |
| 2934 |
} elseif {$module_included && $in_code_env} then { |
| 2935 |
break |
| 2936 |
} |
| 2937 |
} else { |
| 2938 |
% \end{tcl} |
| 2939 |
% In non-verbatim mode, lines are classified based on the first few |
| 2940 |
% characters of the line. |
| 2941 |
% \begin{tcl} |
| 2942 |
switch -glob -- $line { |
| 2943 |
% \end{tcl} |
| 2944 |
% Lines that begin with |%<<| are \package{docstrip} guard lines that |
| 2945 |
% start verbatim mode. The part of the guard line which comes after |
| 2946 |
% the |%<<| is called an end-tag. Verbatim mode ends with the next line |
| 2947 |
% which consists of a percent character followed by this end-tag |
| 2948 |
% \begin{tcl} |
| 2949 |
%<<* { |
| 2950 |
eemenu::docstrip::update_included |
| 2951 |
%<*rowcol> |
| 2952 |
if {$module_included && $in_code_env && $is_safe} then { |
| 2953 |
set safe_pos $cur_pos |
| 2954 |
} |
| 2955 |
%</rowcol> |
| 2956 |
set in_verbatim 1 |
| 2957 |
set end_verb_line "%[string range $line 3 end]" |
| 2958 |
} |
| 2959 |
% \end{tcl} |
| 2960 |
% Lines that begin with |%<*| or |%</| are \package{docstrip} guard |
| 2961 |
% lines that delimit block modules, but they do not contain any code |
| 2962 |
% themselves. The module is pushed onto or popped off the module stack |
| 2963 |
% when the guard line is encountered, but evaluating the guard |
| 2964 |
% expression is deferred until its value is needed. |
| 2965 |
% \begin{tcl} |
| 2966 |
%<[*/]* { |
| 2967 |
if {![regexp {^%<(\*|/)([^>]+)>} $line foo modifier\ |
| 2968 |
expression]}\ |
| 2969 |
then { |
| 2970 |
if {[dialog::yesno "Malformed guard line '$line'\ |
| 2971 |
encountered. Push position?"]}\ |
| 2972 |
% |
| 2973 |
then {eemenu::docstrip::push_bookmarks $cur_pos} |
| 2974 |
} elseif {$modifier=="*"} then { |
| 2975 |
eemenu::docstrip::push_module $expression $cur_pos |
| 2976 |
} else { |
| 2977 |
eemenu::docstrip::pop_module $expression $cur_pos |
| 2978 |
} |
| 2979 |
} |
| 2980 |
% \end{tcl} |
| 2981 |
% Other lines that begin with |%<| are also \package{docstrip} |
| 2982 |
% guard lines, but in these cases the guard is followed by some code |
| 2983 |
% and the guard only affects the code on that particular line. There |
| 2984 |
% must be a |>| somewhere on the line, and the part of the line after |
| 2985 |
% the |>| is code that \package{docstrip} can extract. |
| 2986 |
% \begin{tcl} |
| 2987 |
%<* { |
| 2988 |
if {![regexp {^%<(-|\+|)([^>]+)>(.*)$} $line\ |
| 2989 |
foo modifier expression code]}\ |
| 2990 |
then { |
| 2991 |
if {[dialog::yesno "Malformed guard line '$line'\ |
| 2992 |
encountered. Push position?"]}\ |
| 2993 |
then {eemenu::docstrip::push_bookmarks $cur_pos} |
| 2994 |
} elseif {$in_code_env} then { |
| 2995 |
eemenu::docstrip::update_included |
| 2996 |
if {$module_included &&\ |
| 2997 |
[eemenu::docstrip::eval_guard $expression] !=\ |
| 2998 |
($modifier=="-")} then { |
| 2999 |
set line $code |
| 3000 |
break |
| 3001 |
} |
| 3002 |
} |
| 3003 |
} |
| 3004 |
% \end{tcl} |
| 3005 |
% Remaining lines that begin with |%| are considered comment lines, |
| 3006 |
% but they could technically be metacomment lines (begin with |%%|). |
| 3007 |
% In that case \package{docstrip} would copy the line, but as there |
| 3008 |
% is little point in using this \package{docstrip} features for |
| 3009 |
% lines that the \Tcllogo\ interpreter would be interested in, |
| 3010 |
% the |docstrip| extraction method ignores that subtlety. Comment |
| 3011 |
% lines are ignored unless the |lookAtEnvs| details is |1|, in which |
| 3012 |
% case they are scanned for code environment markup. |
| 3013 |
% \begin{tcl} |
| 3014 |
%* { |
| 3015 |
while {$detA(lookAtEnvs) &&\ |
| 3016 |
[regexp -- $detA(envsRE) $line foo type env line]} { |
| 3017 |
set in_code_env [expr {"$type"=="begin"}] |
| 3018 |
} |
| 3019 |
} |
| 3020 |
% \end{tcl} |
| 3021 |
% Finally, all lines that do not begin with a |%| are code lines. |
| 3022 |
% \begin{tcl} |
| 3023 |
default { |
| 3024 |
if {$in_code_env} then { |
| 3025 |
eemenu::docstrip::update_included |
| 3026 |
if {$module_included} then {break} |
| 3027 |
} |
| 3028 |
} |
| 3029 |
} |
| 3030 |
} |
| 3031 |
% \end{tcl} |
| 3032 |
% That ends the large |switch| command and the large |if|. Now all |
| 3033 |
% that remains in the loop is to update |cur_pos|. |
| 3034 |
% \begin{tcl} |
| 3035 |
%<rowcol> set cur_pos $next_pos |
| 3036 |
} |
| 3037 |
% \end{tcl} |
| 3038 |
% Whenever the procedure gets past the loop, the line that has been |
| 3039 |
% extracted is in |line| and the only thing that remains is to update |
| 3040 |
% the positions. |
| 3041 |
% \begin{tcl} |
| 3042 |
%<*rowcol> |
| 3043 |
if {$is_safe && !$in_verbatim} then {set safe_pos $cur_pos} |
| 3044 |
set cur_pos $next_pos |
| 3045 |
%</rowcol> |
| 3046 |
return $line |
| 3047 |
} |
| 3048 |
% \end{tcl} |
| 3049 |
% \end{proc} |
| 3050 |
% |
| 3051 |
% \begin{proc}{finish} |
| 3052 |
% In addition to the |raw| method |finish| procedure, this |finish| |
| 3053 |
% also unsets the |known| array when there wasn't an error. |
| 3054 |
% \begin{tcl} |
| 3055 |
proc eemenu::docstrip::finish {was_error} { |
| 3056 |
%<!rowcol> eemenu::raw::finish $was_error |
| 3057 |
if {$was_error} then { |
| 3058 |
%<*rowcol> |
| 3059 |
eemenu::multiupvar safe_pos end_pos |
| 3060 |
bringToFront [lindex $safe_pos 0] |
| 3061 |
select [pos::get_standard safe_pos] [pos::get_standard end_pos] |
| 3062 |
markHilite |
| 3063 |
%</rowcol> |
| 3064 |
} else { |
| 3065 |
global eemenu::docstrip::known |
| 3066 |
catch {unset eemenu::docstrip::known} |
| 3067 |
} |
| 3068 |
} |
| 3069 |
% \end{tcl} |
| 3070 |
% \end{proc} |
| 3071 |
% |
| 3072 |
% |
| 3073 |
% \section{Completeness tests} |
| 3074 |
% |
| 3075 |
% \setnamespace{eemenu} |
| 3076 |
% |
| 3077 |
% Unlike the other method types, completion methods are not implemented |
| 3078 |
% as procedures that can be called, but as an expression string stored |
| 3079 |
% in a global variable. The string in question is called |
| 3080 |
% \describestring[var.][eemenu::\meta{method}]{complete}|complete| |
| 3081 |
% and it will be evaluated as an \emph{expression} in the local context |
| 3082 |
% of the |main| procedure. The reason for this different set-up is that |
| 3083 |
% these methods are usually much simpler to handle that way. |
| 3084 |
% |
| 3085 |
% Completion methods are expected to get their data from the following |
| 3086 |
% variables: |
| 3087 |
% \begin{description} |
| 3088 |
% \item[\texttt{lines}] |
| 3089 |
% A list of the lines that have been extracted by not yet evaluated. |
| 3090 |
% This is (at least in theory) what the completion method is testing |
| 3091 |
% for being complete. |
| 3092 |
% \item[\texttt{at\_end}] |
| 3093 |
% A boolean. It is |0| if the extraction has not yet reached the |
| 3094 |
% end, and then it is set to |1|. |
| 3095 |
% \item[\texttt{CMD(complete\_extra)}] |
| 3096 |
% The key--value list of detail settings for completion methods. |
| 3097 |
% None of the methods currently implemented have any detail settings. |
| 3098 |
% \end{description} |
| 3099 |
% |
| 3100 |
% \begin{arrayentry}{complete}{entireSelection} |
| 3101 |
% \setnamespace{eemenu::entireSelection} |
| 3102 |
% \begin{variable}{complete} |
| 3103 |
% The |entireSelection| method says `No' until the entire selection |
| 3104 |
% has been extracted, then `Yes'. It has no detail settings. |
| 3105 |
% \begin{tcl} |
| 3106 |
set eemenu::complete(entireSelection) [list] |
| 3107 |
namespace eval eemenu::entireSelection {} |
| 3108 |
set eemenu::entireSelection::complete {$at_end} |
| 3109 |
% \end{tcl} |
| 3110 |
% \end{variable}\end{arrayentry} |
| 3111 |
% |
| 3112 |
% \begin{arrayentry}{complete}{everyLine} |
| 3113 |
% \setnamespace{eemenu::everyLine} |
| 3114 |
% \begin{variable}{complete} |
| 3115 |
% The |everyLine| method says `Yes' after every line. |
| 3116 |
% \begin{tcl} |
| 3117 |
set eemenu::complete(everyLine) [list] |
| 3118 |
namespace eval eemenu::everyLine {} |
| 3119 |
set eemenu::everyLine::complete {1} |
| 3120 |
% \end{tcl} |
| 3121 |
% \end{variable}\end{arrayentry} |
| 3122 |
% |
| 3123 |
% \begin{arrayentry}{complete}{tclInfoComplete} |
| 3124 |
% \setnamespace{eemenu::tclInfoComplete} |
| 3125 |
% \begin{variable}{complete} |
| 3126 |
% The |tclInfoComplete| method is the only one (defined so far) which |
| 3127 |
% actually cares to look at what has been extracted. It calls the |
| 3128 |
% |info complete| of \Alpha's \Tcllogo\ interpreter. |
| 3129 |
% \begin{tcl} |
| 3130 |
set eemenu::complete(tclInfoComplete) [list] |
| 3131 |
namespace eval eemenu::tclInfoComplete {} |
| 3132 |
set eemenu::tclInfoComplete::complete\ |
| 3133 |
{[info complete [join $lines \n]\n]} |
| 3134 |
% \end{tcl} |
| 3135 |
% \end{variable}\end{arrayentry} |
| 3136 |
% |
| 3137 |
% |
| 3138 |
% \section{Evaluation methods} |
| 3139 |
% |
| 3140 |
% The evaluation\slash execution method is what actually does anything |
| 3141 |
% (all the other methods just move data around). From an input\slash |
| 3142 |
% output perspective it takes the input from the extraction method and |
| 3143 |
% generates the output that the report method should handle. Like |
| 3144 |
% extraction methods, evaluation methods must declare three procedures |
| 3145 |
% for |main| to call. These are: |begin|, |item|, and |end|. All of |
| 3146 |
% these procedures return a \emph{result list}, which has the structure |
| 3147 |
% \begin{quote} |
| 3148 |
% \word{error?} \word{passing} \word{permanent} |
| 3149 |
% \end{quote} |
| 3150 |
% \word{error?} is a boolean that the main executive interprets to see |
| 3151 |
% if there was an error. It is |0| when there wasn't an error. |
| 3152 |
% \word{passing} and \word{permanent} are result strings. \word{passing} |
| 3153 |
% should be suitable for output channels where new results replace old, |
| 3154 |
% whereas \word{permanent} should be suitable for output channels where |
| 3155 |
% the results are appended to each other. If the \word{passing} string |
| 3156 |
% is empty then there is no reason to have it replace a previous |
| 3157 |
% \word{passing} string. If the \word{permanent} string is nonempty |
| 3158 |
% then it must end with a newline character. |
| 3159 |
% |
| 3160 |
% The \describestring[proc][eemenu::\meta{method}]{begin}|begin| |
| 3161 |
% procedure is called to initialize the evaluation process. It has the |
| 3162 |
% syntax |
| 3163 |
% \begin{quote} |
| 3164 |
% |eemenu::|\meta{method}|::begin| \word{details} \word{source} |
| 3165 |
% \end{quote} |
| 3166 |
% where the \word{details} is the key--value list of setting details |
| 3167 |
% and \word{source} is the source window name as returned by the |
| 3168 |
% extraction method |start| procedure. If the result of |begin| has a |
| 3169 |
% nonzero \word{error?} then the corresponding |end| procedure will not |
| 3170 |
% be called. |
| 3171 |
% |
| 3172 |
% The \describestring[proc][eemenu::\meta{method}]{item}|item| |
| 3173 |
% procedure recieves a bunch of code to evaluate. It has the syntax |
| 3174 |
% \begin{quote} |
| 3175 |
% |eemenu::|\meta{method}|::item| \word{lines} |
| 3176 |
% \end{quote} |
| 3177 |
% where \word{lines} is the list of lines of code to evaluate. The |
| 3178 |
% \describestring[proc][eemenu::\meta{method}]{end}|end| procedure is |
| 3179 |
% called when no more lines of code will be sent for evaluation. |end| |
| 3180 |
% takes no arguments. |
| 3181 |
% |
| 3182 |
% It is not necessarily in the call to |item| that the code gets |
| 3183 |
% evaluated. The obvious alternative is that |item| simply stores the |
| 3184 |
% code somewhere, for example by writing it to a temporary file, and |
| 3185 |
% that it is the call to |end| that actually causes the code to be |
| 3186 |
% evaluated. This is an important reason why all the procedures have the |
| 3187 |
% same format for returned data. |
| 3188 |
% |
| 3189 |
% |
| 3190 |
% |
| 3191 |
% \subsection{Internal evaluation} |
| 3192 |
% |
| 3193 |
% The |internalTcl| evaluation method sends the code to \Alpha's internal |
| 3194 |
% \Tcllogo\ interpreter and evaluates it there. |
| 3195 |
% |
| 3196 |
% \begin{arrayentry}[eemenu]{evaluate}{internalTcl} |
| 3197 |
% There are no details for this method. |
| 3198 |
% \begin{tcl} |
| 3199 |
set eemenu::evaluate(internalTcl) [list] |
| 3200 |
% \end{tcl} |
| 3201 |
% \end{arrayentry} |
| 3202 |
% \begin{tcl} |
| 3203 |
namespace eval eemenu::internalTcl {} |
| 3204 |
% \end{tcl} |
| 3205 |
% \setnamespace{eemenu::internalTcl} |
| 3206 |
% |
| 3207 |
% \begin{proc}{begin} |
| 3208 |
% \begin{proc}{end} |
| 3209 |
% Neither the |begin| nor the |end| procedure does anything. |
| 3210 |
% \begin{tcl} |
| 3211 |
proc eemenu::internalTcl::begin {details source} { |
| 3212 |
list 0 "" "" |
| 3213 |
} |
| 3214 |
proc eemenu::internalTcl::end {} {list 0 "" ""} |
| 3215 |
% \end{tcl} |
| 3216 |
% \end{proc}\end{proc} |
| 3217 |
% |
| 3218 |
% \begin{proc}{item} |
| 3219 |
% The |item| procedure actually evaluates the code and suitably |
| 3220 |
% formats the result. |
| 3221 |
% \begin{tcl} |
| 3222 |
proc eemenu::internalTcl::item {lines} { |
| 3223 |
set code [catch [list uplevel #0 [join $lines \n]] res] |
| 3224 |
if {$code == 1} then { |
| 3225 |
% \end{tcl} |
| 3226 |
% If there was an error, the last part of the value of |errorInfo| |
| 3227 |
% will be due to the |uplevel| command. As that command was not |
| 3228 |
% requested by the user, it would be confusing and it is therefore |
| 3229 |
% best to remove it. |
| 3230 |
% \begin{tcl} |
| 3231 |
global errorInfo |
| 3232 |
set L [split $errorInfo \n] |
| 3233 |
set L [lrange $L 0 [expr {[llength $L] - 4}]] |
| 3234 |
list 1 "Tcl eval error: $res"\ |
| 3235 |
"Error: $res\nError info:\n[join $L \n]\n" |
| 3236 |
% \end{tcl} |
| 3237 |
% When there wasn't an error, a distinction is made between the case |
| 3238 |
% of an empty string result (very common, e.g.\ from |proc|) and that |
| 3239 |
% of a nonempty string result. This might seem inconsistent, but in |
| 3240 |
% practice it looks much better. |
| 3241 |
% \begin{tcl} |
| 3242 |
} elseif {[string length $res]} then { |
| 3243 |
list 0 "Tcl eval OK: $res" "$res\n" |
| 3244 |
} else { |
| 3245 |
list 0 "Tcl eval OK." "" |
| 3246 |
} |
| 3247 |
} |
| 3248 |
% \end{tcl} |
| 3249 |
% \end{proc} |
| 3250 |
% |
| 3251 |
% |
| 3252 |
% |
| 3253 |
% \subsection{DoScript AppleEvent evaluation} |
| 3254 |
% |
| 3255 |
% The |doScriptAE| evaluation method sends a |dosc| AppleEvent to some |
| 3256 |
% external application, to have the script evaluated that way. Of |
| 3257 |
% course, this only works if \TclAE\ is available, so this method is |
| 3258 |
% only defined if that is the case. |
| 3259 |
% \begin{tcl} |
| 3260 |
%<atcl7>if {[llength [info commands tclAE::send]]} then { |
| 3261 |
%<!atcl7>if {![catch {package require tclAE}]} then { |
| 3262 |
% \end{tcl} |
| 3263 |
% |
| 3264 |
% \begin{arrayentry}[eemenu]{evaluate}{doScriptAE} |
| 3265 |
% The details for the |doScriptAE| method roughly fall into three |
| 3266 |
% categories: what is the target application, how should the |
| 3267 |
% extracted lines be combined to a script, and what about a reply? |
| 3268 |
% \begin{tcl} |
| 3269 |
set eemenu::evaluate(doScriptAE) [list\ |
| 3270 |
% \end{tcl} |
| 3271 |
% \begin{details}{Evaluate} |
| 3272 |
% \detailitem{targetApp} |
| 3273 |
% This is the appspec of the target application. |
| 3274 |
% \begin{tcl} |
| 3275 |
[eemenu::define_detail Evaluate "Target application"\ |
| 3276 |
targetApp appspec]\ |
| 3277 |
% \end{tcl} |
| 3278 |
% \detailitem{joinString} |
| 3279 |
% The extracted lines is a list, but the script to send should be |
| 3280 |
% a string, so they will have to be joined somehow. This item |
| 3281 |
% offers a choice between some common forms of whitespace. |
| 3282 |
% \begin{tcl} |
| 3283 |
[eemenu::define_detail Evaluate "Join lines using"\ |
| 3284 |
joinString [list menuindex [list Lf Cr CrLf Space]] 1]\ |
| 3285 |
% \end{tcl} |
| 3286 |
% \detailitem{prefix} |
| 3287 |
% This will be prepended to the script sent. It can for example be |
| 3288 |
% used to add some command that takes care of the result. |
| 3289 |
% \begin{tcl} |
| 3290 |
[eemenu::define_detail Evaluate "Prefix" prefix var]\ |
| 3291 |
% \end{tcl} |
| 3292 |
% \detailitem{suffix} |
| 3293 |
% This will be appended to the script sent. |
| 3294 |
% \begin{tcl} |
| 3295 |
[eemenu::define_detail Evaluate "Suffix" suffix var]\ |
| 3296 |
% \end{tcl} |
| 3297 |
% \detailitem{replyQ} |
| 3298 |
% This flag controls whether the method should request a reply to |
| 3299 |
% the AE sent. |
| 3300 |
% \begin{tcl} |
| 3301 |
[eemenu::define_detail Evaluate "Wait for reply" replyQ flag]] |
| 3302 |
% \end{tcl} |
| 3303 |
% \end{details} |
| 3304 |
% \end{arrayentry} |
| 3305 |
% \begin{tcl} |
| 3306 |
namespace eval eemenu::doScriptAE {} |
| 3307 |
% \end{tcl} |
| 3308 |
% \setnamespace{eemenu::doScriptAE} |
| 3309 |
% |
| 3310 |
% |
| 3311 |
% \begin{arrayvar}{A} |
| 3312 |
% The |doScriptAE| method keeps its detail settings, and some derived |
| 3313 |
% quantities, in the |A| array. Those are all the global variables it |
| 3314 |
% has. |
| 3315 |
% \end{arrayvar} |
| 3316 |
% |
| 3317 |
% |
| 3318 |
% \begin{proc}{begin} |
| 3319 |
% The main task of this |begin| procedure is to make sure that the |
| 3320 |
% target application is running. |
| 3321 |
% \begin{tcl} |
| 3322 |
proc eemenu::doScriptAE::begin {details source} { |
| 3323 |
upvar #0 eemenu::doScriptAE::A A |
| 3324 |
array set A {prefix {} suffix {} joinString 1 targetApp {} replyQ 0} |
| 3325 |
array set A $details |
| 3326 |
% \end{tcl} |
| 3327 |
% The |targetApp| is either a quoted application signature or a full |
| 3328 |
% path name. Exactly what will have to be done gets affected by this. |
| 3329 |
% \begin{tcl} |
| 3330 |
if {[regexp {'(....)'} $A(targetApp) foo sig]} then { |
| 3331 |
set err [catch {app::ensureRunning $sig} passing] |
| 3332 |
if {$err == 1} then {set permanent $passing} else { |
| 3333 |
set permanent "" |
| 3334 |
set A(app) $A(targetApp) |
| 3335 |
} |
| 3336 |
} else { |
| 3337 |
set tail [file tail $A(targetApp)] |
| 3338 |
%<*atcl7> |
| 3339 |
if {[info tclversion]<8.0} then { |
| 3340 |
set running\ |
| 3341 |
[regexp "\{\"[quote::Regfind $tail]\" \"" [processes]] |
| 3342 |
} else { |
| 3343 |
%</atcl7> |
| 3344 |
set running 0 |
| 3345 |
foreach pr [processes] { |
| 3346 |
if {![string compare $tail [lindex $pr 0]]} then { |
| 3347 |
set running 1 |
| 3348 |
break |
| 3349 |
} |
| 3350 |
} |
| 3351 |
%<atcl7> } |
| 3352 |
set err 0 |
| 3353 |
set permanent "" |
| 3354 |
set A(app) $tail |
| 3355 |
if {$running} then { |
| 3356 |
set passing "App is running." |
| 3357 |
} elseif {![catch {launch $A(targetApp)} passing]} then { |
| 3358 |
set passing "Launched '$A(targetApp)'" |
| 3359 |
} else { |
| 3360 |
set err 1 |
| 3361 |
if {![file exists $A(targetApp)]} then { |
| 3362 |
set passing "File '$A(targetApp)' not found." |
| 3363 |
} |
| 3364 |
set permanent $passing |
| 3365 |
unset A(app) |
| 3366 |
} |
| 3367 |
} |
| 3368 |
% \end{tcl} |
| 3369 |
% The |joinString| is also decoded. |
| 3370 |
% \begin{tcl} |
| 3371 |
set A(joinString) [lindex [list \n \r \r\n " "] $A(joinString)] |
| 3372 |
return [list $err $passing $permanent] |
| 3373 |
} |
| 3374 |
% \end{tcl} |
| 3375 |
% \end{proc} |
| 3376 |
% |
| 3377 |
% \begin{proc}{item} |
| 3378 |
% The |item| procedure is mainly about formatting data on its way |
| 3379 |
% back and forth. |
| 3380 |
% \begin{tcl} |
| 3381 |
proc eemenu::doScriptAE::item {lines} { |
| 3382 |
upvar #0 eemenu::doScriptAE::A A |
| 3383 |
set script "$A(prefix)[join $lines $A(joinString)]$A(suffix)" |
| 3384 |
if {$A(replyQ)} then { |
| 3385 |
if {[catch {tclAE::build::resultData -t 30000 $A(app) misc dosc\ |
| 3386 |
---- [tclAE::build::TEXT $script]} res]} then { |
| 3387 |
list 1 "Error: $res" "Error: $res\n" |
| 3388 |
} elseif {[string length $res]} then { |
| 3389 |
list 0 $res "$res\n" |
| 3390 |
} else { |
| 3391 |
list 0 "Eval OK." "" |
| 3392 |
} |
| 3393 |
} else { |
| 3394 |
tclAE::send $A(app) misc dosc ---- [tclAE::build::TEXT $script] |
| 3395 |
list 0 "Sent [llength $lines] lines." "" |
| 3396 |
} |
| 3397 |
} |
| 3398 |
% \end{tcl} |
| 3399 |
% \end{proc} |
| 3400 |
% |
| 3401 |
% \begin{proc}{end} |
| 3402 |
% The |end| procedure does nothing |
| 3403 |
% \begin{tcl} |
| 3404 |
proc eemenu::doScriptAE::end {} {list 0 "" ""} |
| 3405 |
% \end{tcl} |
| 3406 |
% \end{proc} |
| 3407 |
% |
| 3408 |
% This ends the |if| begun at the top of this subsection. |
| 3409 |
% \begin{tcl} |
| 3410 |
} |
| 3411 |
% \end{tcl} |
| 3412 |
% |
| 3413 |
% |
| 3414 |
% \subsection{\texttt{send} evaluation} |
| 3415 |
% |
| 3416 |
% The \texttt{send} command can be used to communicate with other Tk |
| 3417 |
% applications via an X-windows server. This is a bit restrictive, but |
| 3418 |
% it is anyway what \AlphaTk\ uses for remote execution of \Tcllogo\ |
| 3419 |
% code, so I suppose it is what we've got. Right now this method is |
| 3420 |
% defined whenever the |send| command exists, but it is not uncommon |
| 3421 |
% that the definition of |send| merely provides communication between |
| 3422 |
% different interpreters in the same application. |
| 3423 |
% \begin{tcl} |
| 3424 |
if {[llength [info commands send]] && [info tclversion]>=8.0} then { |
| 3425 |
% \end{tcl} |
| 3426 |
% |
| 3427 |
% \begin{arrayentry}[eemenu]{evaluate}{tkSend} |
| 3428 |
% Many details for the |doScriptAE| method have natural counterparts |
| 3429 |
% for the |tkSend| method, the main difference lies in the |
| 3430 |
% identification of the target. Whereas \TclAE\ uses static |
| 3431 |
% information (creator code or file name) to identify the target, the |
| 3432 |
% name used by the |send| command is in principle dynamic. The |
| 3433 |
% relevant identifier may change between different times that an |
| 3434 |
% \textsf{EE~menu} command is used. This is handled by providing a |
| 3435 |
% fallback for unknown targets. |
| 3436 |
% \begin{tcl} |
| 3437 |
set eemenu::evaluate(tkSend) [list\ |
| 3438 |
% \end{tcl} |
| 3439 |
% \begin{details}{Evaluate} |
| 3440 |
% \detailitem{target} |
| 3441 |
% This is a string that identifies the target. |
| 3442 |
% \begin{tcl} |
| 3443 |
[eemenu::define_detail Evaluate "Target" target var]\ |
| 3444 |
% \end{tcl} |
| 3445 |
% \detailitem{aliasing} |
| 3446 |
% This detail controls how the |tkSend| method should behave when |
| 3447 |
% |begin| is called but the specified target isn't available. |
| 3448 |
% ``Ask each time'' means present the user with a list of available |
| 3449 |
% targets each time |begin| is called, and use what the user |
| 3450 |
% selected there. ``Ask once'' is similar, but the choice will be |
| 3451 |
% remembered as an \emph{alias} for the specified target (until |
| 3452 |
% \Alpha\ is quited or the alias target no longer is available). |
| 3453 |
% ``Fail'' means fail immediately. |
| 3454 |
% \begin{tcl} |
| 3455 |
[eemenu::define_detail Evaluate "Alias behaviour"\ |
| 3456 |
aliasing [list menu [list "Ask once" "Ask each time" "Fail"]]\ |
| 3457 |
"Ask once" "The thing to do when the target is unavailable."]\ |
| 3458 |
% \end{tcl} |
| 3459 |
% \detailitem{joinString} |
| 3460 |
% The extracted lines is a list, but the script to send should be |
| 3461 |
% a string, so they will have to be joined somehow. This item |
| 3462 |
% offers a choice between some common forms of whitespace. |
| 3463 |
% \begin{tcl} |
| 3464 |
[eemenu::define_detail Evaluate "Join lines using"\ |
| 3465 |
joinString [list menuindex [list Lf Cr CrLf Space]] 0]\ |
| 3466 |
% \end{tcl} |
| 3467 |
% \detailitem{prefix} |
| 3468 |
% This will be prepended to the script sent. It can for example be |
| 3469 |
% used to add some command that takes care of the result. |
| 3470 |
% \begin{tcl} |
| 3471 |
[eemenu::define_detail Evaluate "Prefix" prefix var]\ |
| 3472 |
% \end{tcl} |
| 3473 |
% \detailitem{suffix} |
| 3474 |
% This will be appended to the script sent. |
| 3475 |
% \begin{tcl} |
| 3476 |
[eemenu::define_detail Evaluate "Suffix" suffix var]\ |
| 3477 |
% \end{tcl} |
| 3478 |
% \detailitem{replyQ} |
| 3479 |
% This flag controls whether the method should wait for the |
| 3480 |
% remote shell to return a result. |
| 3481 |
% \begin{tcl} |
| 3482 |
[eemenu::define_detail Evaluate "Wait for reply" replyQ flag 1]] |
| 3483 |
% \end{tcl} |
| 3484 |
% \end{details} |
| 3485 |
% \end{arrayentry} |
| 3486 |
% \begin{tcl} |
| 3487 |
namespace eval eemenu::tkSend {} |
| 3488 |
% \end{tcl} |
| 3489 |
% \setnamespace{eemenu::tkSend} |
| 3490 |
% |
| 3491 |
% \begin{arrayvar}{alias} |
| 3492 |
% The |alias| array is used to keep track of which targets are treated |
| 3493 |
% as aliases for other targets. The index is a value of the |
| 3494 |
% \texttt{target} detail, the entry value is what it should be |
| 3495 |
% replaced by. |
| 3496 |
% \end{arrayvar} |
| 3497 |
% |
| 3498 |
% \begin{variable}{last_target} |
| 3499 |
% The |last_target| variable contains the name of the most recently |
| 3500 |
% selected target. This is so that the relevant |listpick| dialog |
| 3501 |
% can ``remember'' the user's preference in this respect. |
| 3502 |
% \begin{tcl} |
| 3503 |
set eemenu::tkSend::last_target {} |
| 3504 |
% \end{tcl} |
| 3505 |
% \end{variable} |
| 3506 |
% |
| 3507 |
% \begin{arrayvar}{A} |
| 3508 |
% The |tkSend| method keeps its detail settings, and some derived |
| 3509 |
% quantities, in the |A| array for convenience of access. |
| 3510 |
% \end{arrayvar} |
| 3511 |
% |
| 3512 |
% |
| 3513 |
% \begin{proc}{begin} |
| 3514 |
% The main task of this |begin| procedure is to verify that the target |
| 3515 |
% is available. |
| 3516 |
% \begin{tcl} |
| 3517 |
proc eemenu::tkSend::begin {details source} { |
| 3518 |
eemenu::multiupvar A alias last_target |
| 3519 |
array set A {prefix {} suffix {} joinString 1 target {} replyQ 1\ |
| 3520 |
aliasing "Ask once"} |
| 3521 |
array set A $details |
| 3522 |
% \end{tcl} |
| 3523 |
% The treatment of aliases depend on the |aliasing| setting. If it is |
| 3524 |
% \texttt{Ask once} then an alias will be used even if a target with |
| 3525 |
% the given name is available. The rationale for this is that the user |
| 3526 |
% has specified that the commands should be sent to that application. |
| 3527 |
% \begin{tcl} |
| 3528 |
set T [lsort -dictionary [winfo interps]] |
| 3529 |
switch -- $A(aliasing) "Ask each time" { |
| 3530 |
if {[lsearch -exact $T $A(target)]>=0} then { |
| 3531 |
set target $A(target) |
| 3532 |
} |
| 3533 |
} "Fail" { |
| 3534 |
if {[lsearch -exact $T $A(target)]>=0} then { |
| 3535 |
set target $A(target) |
| 3536 |
} else { |
| 3537 |
set passing "Target '$A(target)' unavailable." |
| 3538 |
return [list 1 $passing $passing] |
| 3539 |
} |
| 3540 |
} default { |
| 3541 |
set target $A(target) |
| 3542 |
if {[info exists alias($target)]} then { |
| 3543 |
set target $alias($target) |
| 3544 |
} |
| 3545 |
if {[lsearch -exact $T $target]<0} then {unset target} |
| 3546 |
} |
| 3547 |
% \end{tcl} |
| 3548 |
% If the local |target| variable is not set at this point then it is |
| 3549 |
% time to ask the user. |
| 3550 |
% \begin{tcl} |
| 3551 |
if {![info exists target]} then { |
| 3552 |
if {[catch {listpick -p "Target '$A(target)' unavailable.\ |
| 3553 |
Please pick a new one." -L [list $last_target]\ |
| 3554 |
[linsert $T end "------------------" "Launch new shell"]}\ |
| 3555 |
target]} then { |
| 3556 |
return [list 1 "Canceled" ""] |
| 3557 |
} |
| 3558 |
switch -exact -- $target\ |
| 3559 |
"------------------" - "Launch new shell" { |
| 3560 |
set before [clock seconds] |
| 3561 |
app::launchElseTryThese [uplevel #0 {set tclshSigs}] tclshSig\ |
| 3562 |
{Please locate the remote Tcl application} |
| 3563 |
while {![string compare $T\ |
| 3564 |
[lsort -dictionary [winfo interps]]] &&\ |
| 3565 |
[clock seconds] - $before < 60} {update} |
| 3566 |
set T2 [lsort -dictionary [winfo interps]] |
| 3567 |
if {![string compare $T $T2]} then { |
| 3568 |
return [list 1 {Timed out; no new shell started within\ |
| 3569 |
60 seconds.} ""] |
| 3570 |
} |
| 3571 |
foreach target $T2 t $T { |
| 3572 |
if {[string compare $target $t]} then {break} |
| 3573 |
} |
| 3574 |
set passing "Launched new shell '$target'." |
| 3575 |
} default { |
| 3576 |
set passing "Sending code to '$target'." |
| 3577 |
} |
| 3578 |
% \end{tcl} |
| 3579 |
% The last |foreach| above locates the first |target| in |$T2| which |
| 3580 |
% is not in |$T|. This |foreach| is the reason this code requires |
| 3581 |
% \Tcllogo\,8. |
| 3582 |
% |
| 3583 |
% Now the target should be stored in the necessary variables. |
| 3584 |
% \begin{tcl} |
| 3585 |
set last_target $target |
| 3586 |
if {![string compare $A(aliasing) "Ask once"]} then { |
| 3587 |
set alias($A(target)) $target |
| 3588 |
} |
| 3589 |
} else { |
| 3590 |
set passing "Sending code to '$target'." |
| 3591 |
} |
| 3592 |
set A(target) $target |
| 3593 |
% \end{tcl} |
| 3594 |
% The |joinString| is also decoded. |
| 3595 |
% \begin{tcl} |
| 3596 |
set A(joinString) [lindex [list \n \r \r\n " "] $A(joinString)] |
| 3597 |
return [list 0 $passing ""] |
| 3598 |
} |
| 3599 |
% \end{tcl} |
| 3600 |
% \end{proc} |
| 3601 |
% |
| 3602 |
% \begin{proc}{item} |
| 3603 |
% The |item| procedure is mainly about formatting data on its way |
| 3604 |
% back and forth. |
| 3605 |
% \begin{tcl} |
| 3606 |
proc eemenu::tkSend::item {lines} { |
| 3607 |
upvar #0 eemenu::tkSend::A A |
| 3608 |
set script "$A(prefix)[join $lines $A(joinString)]$A(suffix)" |
| 3609 |
if {$A(replyQ)} then { |
| 3610 |
if {[catch {send $A(target) $script} res]} then { |
| 3611 |
list 1 "Error: $res" "Error: $res\n" |
| 3612 |
} elseif {[string length $res]} then { |
| 3613 |
list 0 "Eval OK: $res" "$res\n" |
| 3614 |
} else { |
| 3615 |
list 0 "Eval OK." "" |
| 3616 |
} |
| 3617 |
} else { |
| 3618 |
send -async $A(target) $script |
| 3619 |
list 0 "Sent [llength $lines] lines." "" |
| 3620 |
} |
| 3621 |
} |
| 3622 |
% \end{tcl} |
| 3623 |
% \end{proc} |
| 3624 |
% |
| 3625 |
% \begin{proc}{end} |
| 3626 |
% The |end| procedure does nothing |
| 3627 |
% \begin{tcl} |
| 3628 |
proc eemenu::tkSend::end {} {list 0 "" ""} |
| 3629 |
% \end{tcl} |
| 3630 |
% \end{proc} |
| 3631 |
% |
| 3632 |
% This ends the |if| begun at the top of this subsection. |
| 3633 |
% \begin{tcl} |
| 3634 |
} |
| 3635 |
% \end{tcl} |
| 3636 |
% |
| 3637 |
% \subsubsection*{Test code} |
| 3638 |
% |
| 3639 |
% The code below fakes definitions of |send| and |winfo interps| using |
| 3640 |
% \Tcllogo\AE\ and |processes| for the purpose of testing the above code. |
| 3641 |
% \begin{tcl} |
| 3642 |
%<*sendtest> |
| 3643 |
proc send {target cmd args} { |
| 3644 |
set sync 1 |
| 3645 |
if {![string compare $target -async]} then { |
| 3646 |
set sync 0 |
| 3647 |
set target $cmd |
| 3648 |
set cmd [lindex $args 0] |
| 3649 |
} |
| 3650 |
set cmd [tclAE::build::TEXT $cmd] |
| 3651 |
if {$sync} then { |
| 3652 |
tclAE::build::resultData -t 30000 $target misc dosc ---- $cmd |
| 3653 |
} else { |
| 3654 |
tclAE::send $target misc dosc ---- $cmd |
| 3655 |
} |
| 3656 |
} |
| 3657 |
proc winfo {subcmd args} { |
| 3658 |
if {[string compare $subcmd "interps"]} then { |
| 3659 |
error "Unimplemented winfo subcommand: $subcmd" |
| 3660 |
} |
| 3661 |
set res [list] |
| 3662 |
global tclshSigs |
| 3663 |
foreach pr [processes] { |
| 3664 |
if {[lsearch -exact $tclshSigs [lindex $pr 1]]>=0} then { |
| 3665 |
lappend res [file tail [lindex $pr 0]] |
| 3666 |
} |
| 3667 |
} |
| 3668 |
return $res |
| 3669 |
} |
| 3670 |
%</sendtest> |
| 3671 |
% \end{tcl} |
| 3672 |
% |
| 3673 |
% |
| 3674 |
% \subsection{\texttt{dde} evaluation} |
| 3675 |
% |
| 3676 |
% Dynamic Data Exchange (\texttt{dde}) is, as I understand it, the |
| 3677 |
% Windoze equivalent of AppleEvents, although the events sent have much |
| 3678 |
% less structure. The machinery needed here is quite similar to that |
| 3679 |
% for \texttt{send} evaluation, but there are a few extra details that |
| 3680 |
% can be set. |
| 3681 |
% \changes{v\,0.1.1}{2002/07/21}{Renamed the \textsf{Dde} method to |
| 3682 |
% \textsf{Windoze DDE}. (LH)} |
| 3683 |
% |
| 3684 |
% \begin{tcl} |
| 3685 |
if {[llength [info commands dde]] && [info tclversion]>=8.0} then { |
| 3686 |
% \end{tcl} |
| 3687 |
% |
| 3688 |
% \begin{arrayentry}[eemenu]{evaluate}{windozeDDE} |
| 3689 |
% The details for the |windozeDDE| method constitute a superset of those for |
| 3690 |
% the |tkSend| method. |
| 3691 |
% \begin{tcl} |
| 3692 |
set eemenu::evaluate(windozeDDE) [list\ |
| 3693 |
% \end{tcl} |
| 3694 |
% \begin{details}{Evaluate} |
| 3695 |
% \detailitem{service} |
| 3696 |
% This is a string that specifies the service to use. |
| 3697 |
% \begin{tcl} |
| 3698 |
[eemenu::define_detail Evaluate "Service" service var "TclEval"]\ |
| 3699 |
% \end{tcl} |
| 3700 |
% \detailitem{target} |
| 3701 |
% This is a string that identifies the target application, or as |
| 3702 |
% it appears to be called, the ``topic''. |
| 3703 |
% \begin{tcl} |
| 3704 |
[eemenu::define_detail Evaluate "Target" target var]\ |
| 3705 |
% \end{tcl} |
| 3706 |
% \detailitem{aliasing} |
| 3707 |
% This detail controls how the |windozeDDE| method should behave when |
| 3708 |
% |begin| is called but the specified target isn't available. |
| 3709 |
% ``Ask each time'' means present the user with a list of available |
| 3710 |
% targets each time |begin| is called, and use what the user |
| 3711 |
% selected there. ``Ask once'' is similar, but the choice will be |
| 3712 |
% remembered as an \emph{alias} for the specified target (until |
| 3713 |
% \Alpha\ is quited or the alias target no longer is available). |
| 3714 |
% ``Fail'' means fail immediately. |
| 3715 |
% \begin{tcl} |
| 3716 |
[eemenu::define_detail Evaluate "Alias behaviour"\ |
| 3717 |
aliasing [list menu [list "Ask once" "Ask each time" "Fail"]]\ |
| 3718 |
"Ask once" "The thing to do when the target is unavailable."]\ |
| 3719 |
% \end{tcl} |
| 3720 |
% \detailitem{launchCmd} |
| 3721 |
% This is a \Tcllogo\ command which, when executed by \Alpha, |
| 3722 |
% should launch an application that provides a new target for |
| 3723 |
% the given service. The command is evaluated at a global level. |
| 3724 |
% If it is an empty string, then no option for launching will be |
| 3725 |
% presented in the target selection dialog. |
| 3726 |
% \begin{tcl} |
| 3727 |
[eemenu::define_detail Evaluate "Launch command" launchCmd var2]\ |
| 3728 |
% \end{tcl} |
| 3729 |
% \detailitem{joinString} |
| 3730 |
% The extracted lines is a list, but the script to send should be |
| 3731 |
% a string, so they will have to be joined somehow. This item |
| 3732 |
% offers a choice between some common forms of whitespace. |
| 3733 |
% \begin{tcl} |
| 3734 |
[eemenu::define_detail Evaluate "Join lines using"\ |
| 3735 |
joinString [list menuindex [list Lf Cr CrLf Space]] 2]\ |
| 3736 |
% \end{tcl} |
| 3737 |
% \detailitem{prefix} |
| 3738 |
% This will be prepended to the script sent. It can for example be |
| 3739 |
% used to add some command that takes care of the result. |
| 3740 |
% \begin{tcl} |
| 3741 |
[eemenu::define_detail Evaluate "Prefix" prefix var]\ |
| 3742 |
% \end{tcl} |
| 3743 |
% \detailitem{suffix} |
| 3744 |
% This will be appended to the script sent. |
| 3745 |
% \begin{tcl} |
| 3746 |
[eemenu::define_detail Evaluate "Suffix" suffix var]\ |
| 3747 |
% \end{tcl} |
| 3748 |
% \detailitem{request} |
| 3749 |
% This is the name of the item to request as result from the |
| 3750 |
% evaluation. If it is an empty string then no request is made. |
| 3751 |
% \begin{tcl} |
| 3752 |
[eemenu::define_detail Evaluate "Requested data" request var]] |
| 3753 |
% \end{tcl} |
| 3754 |
% \end{details} |
| 3755 |
% \end{arrayentry} |
| 3756 |
% \begin{tcl} |
| 3757 |
namespace eval eemenu::windozeDDE {} |
| 3758 |
% \end{tcl} |
| 3759 |
% \setnamespace{eemenu::windozeDDE} |
| 3760 |
% |
| 3761 |
% \begin{arrayvar}{alias} |
| 3762 |
% The |alias| array is used to keep track of which targets are treated |
| 3763 |
% as aliases for other targets. The index is a value of the |
| 3764 |
% \texttt{target} detail, the entry value is what it should be |
| 3765 |
% replaced by. |
| 3766 |
% \end{arrayvar} |
| 3767 |
% |
| 3768 |
% \begin{variable}{last_target} |
| 3769 |
% The |last_target| variable contains the name of the most recently |
| 3770 |
% selected target. This is so that the relevant |listpick| dialog |
| 3771 |
% can ``remember'' the user's preference in this respect. |
| 3772 |
% \begin{tcl} |
| 3773 |
set eemenu::windozeDDE::last_target {} |
| 3774 |
% \end{tcl} |
| 3775 |
% \end{variable} |
| 3776 |
% |
| 3777 |
% \begin{arrayvar}{A} |
| 3778 |
% The |windozeDDE| method keeps its detail settings, and some derived |
| 3779 |
% quantities, in the |A| array for convenience of access. |
| 3780 |
% \end{arrayvar} |
| 3781 |
% |
| 3782 |
% |
| 3783 |
% \begin{proc}{begin} |
| 3784 |
% The main task of this |begin| procedure is to verify that the target |
| 3785 |
% is available. |
| 3786 |
% \begin{tcl} |
| 3787 |
proc eemenu::windozeDDE::begin {details source} { |
| 3788 |
eemenu::multiupvar A alias last_target |
| 3789 |
array set A {service {} target {} aliasing "Ask once" launchCmd {}\ |
| 3790 |
prefix {} suffix {} joinString 2 request {}} |
| 3791 |
array set A $details |
| 3792 |
if {![string length $A(service)]} then { |
| 3793 |
return [list 1 "No service has been specified." ""] |
| 3794 |
} |
| 3795 |
% \end{tcl} |
| 3796 |
% The treatment of aliases depend on the |aliasing| setting. If it is |
| 3797 |
% \texttt{Ask once} then an alias will be used even if a target with |
| 3798 |
% the given name is available. The rationale for this is that the user |
| 3799 |
% has specified that the commands should be sent to that application. |
| 3800 |
% \begin{tcl} |
| 3801 |
set T [list] |
| 3802 |
foreach st [dde services $A(service) {}] {lappend T [lindex $st 1]} |
| 3803 |
set T [lsort -dictionary $T] |
| 3804 |
switch -- $A(aliasing) "Ask each time" { |
| 3805 |
if {[lsearch -exact $T $A(target)]>=0} then { |
| 3806 |
set target $A(target) |
| 3807 |
} |
| 3808 |
} "Fail" { |
| 3809 |
if {[lsearch -exact $T $A(target)]>=0} then { |
| 3810 |
set target $A(target) |
| 3811 |
} else { |
| 3812 |
set passing "Target '$A(target)' unavailable." |
| 3813 |
return [list 1 $passing $passing] |
| 3814 |
} |
| 3815 |
} default { |
| 3816 |
set target $A(target) |
| 3817 |
if {[info exists alias($target)]} then { |
| 3818 |
set target $alias($target) |
| 3819 |
} |
| 3820 |
if {[lsearch -exact $T $target]<0} then {unset target} |
| 3821 |
} |
| 3822 |
% \end{tcl} |
| 3823 |
% If the local |target| variable is not set at this point then it is |
| 3824 |
% time to ask the user. |
| 3825 |
% \begin{tcl} |
| 3826 |
if {![info exists target]} then { |
| 3827 |
set T2 $T |
| 3828 |
if {[string length $A(launchCmd)]} then { |
| 3829 |
if {[llength $T2]} then {lappend T2 "------------------"} |
| 3830 |
lappend T2 "Launch another" |
| 3831 |
} |
| 3832 |
if {![llength $T2]} then { |
| 3833 |
return [list 1 "No '$A(service)' targets are, or could be\ |
| 3834 |
made, available." ""] |
| 3835 |
} |
| 3836 |
if {[catch {listpick -p "Target '$A(target)' unavailable.\ |
| 3837 |
Please pick a new one." -L [list $last_target] $T2}\ |
| 3838 |
target]} then { |
| 3839 |
return [list 1 "Canceled" ""] |
| 3840 |
} |
| 3841 |
switch -exact -- $target\ |
| 3842 |
"------------------" - "Launch another" { |
| 3843 |
set before [clock seconds] |
| 3844 |
uplevel #0 $A(launchCmd) |
| 3845 |
set target {} |
| 3846 |
while {[clock seconds] - $before < 60 &&\ |
| 3847 |
![string length $target]} { |
| 3848 |
foreach st [dde services $A(service) {}] { |
| 3849 |
if {[lsearch -exact $T [lindex $st 1]]<0} then { |
| 3850 |
set target [lindex $st 1] |
| 3851 |
break |
| 3852 |
} |
| 3853 |
} |
| 3854 |
update |
| 3855 |
} |
| 3856 |
if {![string length $target]} then { |
| 3857 |
return [list 1 {Timed out; no new target launched within\ |
| 3858 |
60 seconds.} ""] |
| 3859 |
} |
| 3860 |
set passing "Launched new shell '$target'." |
| 3861 |
} default { |
| 3862 |
set passing "Sending code to '$target'." |
| 3863 |
} |
| 3864 |
% \end{tcl} |
| 3865 |
% The last |foreach| above locates the first |target| in |$T2| which |
| 3866 |
% is not in |$T|. This |foreach| is the reason this code requires |
| 3867 |
% \Tcllogo\,8. |
| 3868 |
% |
| 3869 |
% Now the target should be stored in the necessary variables. |
| 3870 |
% \begin{tcl} |
| 3871 |
set last_target $target |
| 3872 |
if {![string compare $A(aliasing) "Ask once"]} then { |
| 3873 |
set alias($A(target)) $target |
| 3874 |
} |
| 3875 |
} else { |
| 3876 |
set passing "Sending code to '$target'." |
| 3877 |
} |
| 3878 |
set A(target) $target |
| 3879 |
% \end{tcl} |
| 3880 |
% The |joinString| is also decoded. |
| 3881 |
% \begin{tcl} |
| 3882 |
set A(joinString) [lindex [list \n \r \r\n " "] $A(joinString)] |
| 3883 |
return [list 0 $passing ""] |
| 3884 |
} |
| 3885 |
% \end{tcl} |
| 3886 |
% \end{proc} |
| 3887 |
% |
| 3888 |
% \begin{proc}{item} |
| 3889 |
% The |item| procedure is mainly about formatting data on its way |
| 3890 |
% back and forth. |
| 3891 |
% \begin{tcl} |
| 3892 |
proc eemenu::windozeDDE::item {lines} { |
| 3893 |
upvar #0 eemenu::windozeDDE::A A |
| 3894 |
set script "$A(prefix)[join $lines $A(joinString)]$A(suffix)" |
| 3895 |
if {[catch {dde execute $A(service) $A(target) $script} res]} then { |
| 3896 |
list 1 "dde error: $res" "$res\n" |
| 3897 |
} elseif {![string length $A(request)]} then { |
| 3898 |
list 0 "Sent [llength $lines] lines." "" |
| 3899 |
} else { |
| 3900 |
if {[catch {dde request $A(service) $A(target) $A(request)} res]}\ |
| 3901 |
then { |
| 3902 |
list 1 "dde error: $res" "dde error: $res\n" |
| 3903 |
} elseif {[string length $res]} then { |
| 3904 |
list 0 $res "$res\n" |
| 3905 |
} else { |
| 3906 |
list 0 "Eval OK." "" |
| 3907 |
} |
| 3908 |
} |
| 3909 |
} |
| 3910 |
% \end{tcl} |
| 3911 |
% \end{proc} |
| 3912 |
% |
| 3913 |
% \begin{proc}{end} |
| 3914 |
% The |end| procedure does nothing |
| 3915 |
% \begin{tcl} |
| 3916 |
proc eemenu::windozeDDE::end {} {list 0 "" ""} |
| 3917 |
% \end{tcl} |
| 3918 |
% \end{proc} |
| 3919 |
% |
| 3920 |
% This ends the |if| begun at the top of this subsection. |
| 3921 |
% \begin{tcl} |
| 3922 |
} |
| 3923 |
% \end{tcl} |
| 3924 |
% |
| 3925 |
% \subsubsection*{Test code} |
| 3926 |
% |
| 3927 |
% The code below fakes a definition of |dde| using |interp|. |
| 3928 |
% \begin{tcl} |
| 3929 |
%<*ddetest> |
| 3930 |
proc dde {subcmd args} { |
| 3931 |
switch -- $subcmd servername { |
| 3932 |
error "dde servername is not implemented." |
| 3933 |
} execute { |
| 3934 |
if {[llength $args] != 3} then { |
| 3935 |
error "Wrong number of arguments for dde execute." |
| 3936 |
} |
| 3937 |
if {"TclEval" != [lindex $args 0]} then { |
| 3938 |
error "Unknown servername: [lindex $args 0]" |
| 3939 |
} |
| 3940 |
interp eval [lindex $args 1] [lindex $args 2] |
| 3941 |
} poke { |
| 3942 |
if {[llength $args] != 4} then { |
| 3943 |
error "Wrong number of arguments for dde poke." |
| 3944 |
} |
| 3945 |
if {"TclEval" != [lindex $args 0]} then { |
| 3946 |
error "Unknown servername: [lindex $args 0]" |
| 3947 |
} |
| 3948 |
interp eval [lindex $args 1]\ |
| 3949 |
[list set [lindex $args 2] [lindex $args 3]] |
| 3950 |
} request { |
| 3951 |
if {[llength $args] != 3} then { |
| 3952 |
error "Wrong number of arguments for dde request." |
| 3953 |
} |
| 3954 |
if {"TclEval" != [lindex $args 0]} then { |
| 3955 |
error "Unknown servername: [lindex $args 0]" |
| 3956 |
} |
| 3957 |
interp eval [lindex $args 1] [list set [lindex $args 2]] |
| 3958 |
} services { |
| 3959 |
if {[llength $args] != 2} then { |
| 3960 |
error "Wrong number of arguments for dde services." |
| 3961 |
} |
| 3962 |
set server [lindex $args 0] |
| 3963 |
if {[string length $server] && $server != "TclEval"} then { |
| 3964 |
return "" |
| 3965 |
} |
| 3966 |
set topic [lindex $args 1] |
| 3967 |
if {![string length $topic]} then { |
| 3968 |
set res [list] |
| 3969 |
foreach slave [interp slaves] { |
| 3970 |
lappend res [list TclEval $slave] |
| 3971 |
} |
| 3972 |
return $res |
| 3973 |
} elseif {[interp exists $topic]} then { |
| 3974 |
return [list [list TclEval $topic]] |
| 3975 |
} else { |
| 3976 |
return "" |
| 3977 |
} |
| 3978 |
} default { |
| 3979 |
error "Unimplemented subcommand: $subcmd" |
| 3980 |
} |
| 3981 |
} |
| 3982 |
%</ddetest> |
| 3983 |
% \end{tcl} |
| 3984 |
% |
| 3985 |
% |
| 3986 |
% \section{Report methods} |
| 3987 |
% \label{Sec:Report} |
| 3988 |
% |
| 3989 |
% The report method takes care of sending output to the user. Like |
| 3990 |
% extraction and evaluation methods there is one `begin' procedure |
| 3991 |
% |log_open| and one `end' procedure |log_close| for each method, but |
| 3992 |
% there are actually two `iterate' procedures. This is because the |
| 3993 |
% extracted code is logged using |log_code| \emph{before} it is |
| 3994 |
% evaluated, whereas the result is only known after the code has been |
| 3995 |
% evaluated and is then logged using |log_result|. |
| 3996 |
% |
| 3997 |
% The \describestring[proc][eemenu::\meta{method}]{log_open}|log_open| |
| 3998 |
% procedure has the syntax |
| 3999 |
% \begin{quote} |
| 4000 |
% |eemenu::|\meta{method}|::log_open| \word{details} \word{source} |
| 4001 |
% \end{quote} |
| 4002 |
% where the \word{details} is the key--value list of setting details |
| 4003 |
% and \word{source} is the source window name as returned by the |
| 4004 |
% extraction method |start| procedure. There is no result from this |
| 4005 |
% procedure, but if there is something wrong with its argument then it |
| 4006 |
% may stop the \eemenu\ command by returning with an error. |
| 4007 |
% |
| 4008 |
% The reason the \word{source} argument is provided is that some report |
| 4009 |
% methods might want to make some aspect of their output, such as for |
| 4010 |
% example a window title or log file name, dependent on the input source. |
| 4011 |
% Neither the |statusLine| nor the |logWindow| method do this, though. |
| 4012 |
% |
| 4013 |
% The \describestring[proc][eemenu::\meta{method}]{log_code}|log_code| |
| 4014 |
% procedure has the syntax |
| 4015 |
% \begin{quote} |
| 4016 |
% |eemenu::|\meta{method}|::log_code| \word{lines} |
| 4017 |
% \end{quote} |
| 4018 |
% where \word{lines} is the list of lines that will be sent to the |
| 4019 |
% evaluation method. The |
| 4020 |
% \describestring[proc][eemenu::\meta{method}]{log_result}|log_result| |
| 4021 |
% procedure has the syntax |
| 4022 |
% \begin{quote} |
| 4023 |
% |eemenu::|\meta{method}|::log_result| \word{error?} |
| 4024 |
% \word{passing result} \word{permanent result} |
| 4025 |
% \end{quote} |
| 4026 |
% where the \word{error?} is |1| if there was an evaluation error and |
| 4027 |
% |0| otherwise. The \word{passing result} is a result string that |
| 4028 |
% describes the current state of the evaluation process; it is meant |
| 4029 |
% to be replaced by the next \word{passing result} the next time |
| 4030 |
% |log_result| is called. By constrast the \word{permanent result} is |
| 4031 |
% meant to be accumulated for each call to |log_result|. Whether a |
| 4032 |
% report method uses one or the other (or both) depends on which makes |
| 4033 |
% most sense for the output channels it employs. If the \word{passing |
| 4034 |
% result} string is empty then it should not replace a previous |
| 4035 |
% \word{passing result} string. If the \word{permanent} string is |
| 4036 |
% nonempty then it must end with a newline character. |
| 4037 |
% |
| 4038 |
% The \describestring[proc][eemenu::\meta{method}]{log_close}|log_close| |
| 4039 |
% procedure is responsible for cleaning up after the method, but only |
| 4040 |
% to the extent that this is necessary. If |log_open| opened a file then |
| 4041 |
% |log_close| should close it, but if |log_open| merely opened a window |
| 4042 |
% then |log_close| should most likely not close it since the user will |
| 4043 |
% want to see what is written in that window. The syntax is simply |
| 4044 |
% \begin{quote} |
| 4045 |
% |eemenu::|\meta{method}|::log_close| |
| 4046 |
% \end{quote} |
| 4047 |
% and there is no result from the procedure. |
| 4048 |
% |
| 4049 |
% |
| 4050 |
% |
| 4051 |
% \subsection{Status line reports} |
| 4052 |
% |
| 4053 |
% The |statusLine| method shows the \word{passing result}s on the |
| 4054 |
% status line, but does nothing else. |
| 4055 |
% |
| 4056 |
% \setnamespace{eemenu::statusLine} |
| 4057 |
% \begin{arrayentry}[eemenu]{report}{statusLine} |
| 4058 |
% There are no details settings for this method. |
| 4059 |
% \begin{tcl} |
| 4060 |
namespace eval eemenu::statusLine {} |
| 4061 |
set eemenu::report(statusLine) [list] |
| 4062 |
% \end{tcl} |
| 4063 |
% \end{arrayentry} |
| 4064 |
% |
| 4065 |
% \begin{proc}{log_open} |
| 4066 |
% \begin{proc}{log_close} |
| 4067 |
% \begin{proc}{log_code} |
| 4068 |
% \begin{proc}{log_result} |
| 4069 |
% Only the |log_result| procedure needs to do anything. |
| 4070 |
% \begin{tcl} |
| 4071 |
proc eemenu::statusLine::log_open {details source} {} |
| 4072 |
proc eemenu::statusLine::log_close {} {} |
| 4073 |
proc eemenu::statusLine::log_code {lines} {} |
| 4074 |
proc eemenu::statusLine::log_result {was_err passing permanent} { |
| 4075 |
if {[string length $passing]} then {status::msg $passing} |
| 4076 |
} |
| 4077 |
% \end{tcl} |
| 4078 |
% \end{proc}\end{proc}\end{proc}\end{proc} |
| 4079 |
% |
| 4080 |
% |
| 4081 |
% \subsection{Log window reports} |
| 4082 |
% |
| 4083 |
% The |logWindow| method opens a particular window and inserts |
| 4084 |
% everything that is logged there. |
| 4085 |
% |
| 4086 |
% \begin{arrayentry}[eemenu]{report}{logWindow} |
| 4087 |
% There are three detail settings for |logWindow| reports. |
| 4088 |
% \begin{tcl} |
| 4089 |
set eemenu::report(logWindow) [list\ |
| 4090 |
% \end{tcl} |
| 4091 |
% \begin{details}{Report} |
| 4092 |
% \detailitem{winName} |
| 4093 |
% This is the name of the log window. |
| 4094 |
% \begin{tcl} |
| 4095 |
[eemenu::define_detail Report "Window name" winName var "Log"]\ |
| 4096 |
% \end{tcl} |
| 4097 |
% \detailitem{winMode} |
| 4098 |
% This is the mode to use for the log window. |
| 4099 |
% \begin{tcl} |
| 4100 |
[eemenu::define_detail Report "Window mode" winMode mode "Text"]\ |
| 4101 |
% \end{tcl} |
| 4102 |
% \detailitem{prompt} |
| 4103 |
% This is a ``prompt'' string that will be put at the beginning of |
| 4104 |
% each code line. |
| 4105 |
% \begin{tcl} |
| 4106 |
[eemenu::define_detail Report "Prompt" prompt var\ |
| 4107 |
"[text::Ascii 200 1] "]\ |
| 4108 |
% \end{tcl} |
| 4109 |
% \detailitem{antiprompt} |
| 4110 |
% This is a string that will be put at the beginning of each line |
| 4111 |
% that is not a code line. |
| 4112 |
% \begin{tcl} |
| 4113 |
[eemenu::define_detail Report "Antiprompt" antiprompt var ""]] |
| 4114 |
% \end{tcl} |
| 4115 |
% \end{details} |
| 4116 |
% \end{arrayentry} |
| 4117 |
% \begin{tcl} |
| 4118 |
namespace eval eemenu::logWindow {} |
| 4119 |
% \end{tcl} |
| 4120 |
% \setnamespace{eemenu::logWindow} |
| 4121 |
% |
| 4122 |
% \begin{arrayvar}{A} |
| 4123 |
% The |logWindow| method keeps its detail settings in the |A| |
| 4124 |
% array. Those are all the global variables it has. |
| 4125 |
% \end{arrayvar} |
| 4126 |
% |
| 4127 |
% \begin{proc}{log_open} |
| 4128 |
% This procedure opens the log window (if it isn't open already) |
| 4129 |
% and positions the cursor at the end of the window. This is |
| 4130 |
% assumed to be at the beginning of a line. |
| 4131 |
% \begin{tcl} |
| 4132 |
proc eemenu::logWindow::log_open {details source} { |
| 4133 |
upvar #0 eemenu::logWindow::A A |
| 4134 |
array set A {winName {Log window} prompt {} antiprompt {}} |
| 4135 |
array set A $details |
| 4136 |
set win $A(winName) |
| 4137 |
if {[lsearch -exact [winNames] $win] == -1} then { |
| 4138 |
set call [list new -n $win -shell 1] |
| 4139 |
if {[mode::exists $A(winMode)]} then {lappend call -m $A(winMode)} |
| 4140 |
eval $call |
| 4141 |
} |
| 4142 |
set t [maxPos -w $win] |
| 4143 |
select -w $win $t $t |
| 4144 |
} |
| 4145 |
% \end{tcl} |
| 4146 |
% \end{proc} |
| 4147 |
% |
| 4148 |
% \begin{proc}{log_code} |
| 4149 |
% The |log_code| procedure inserts the lines at the current position |
| 4150 |
% in the file. This will be at the end of the file, unless the |
| 4151 |
% evaluation modifies this. |
| 4152 |
% \begin{tcl} |
| 4153 |
proc eemenu::logWindow::log_code {lines} { |
| 4154 |
upvar #0 eemenu::logWindow::A A |
| 4155 |
insertText -w $A(winName) "$A(prompt)[join $lines "\n$A(prompt)"]\n" |
| 4156 |
} |
| 4157 |
% \end{tcl} |
| 4158 |
% \end{proc} |
| 4159 |
% |
| 4160 |
% \begin{proc}{log_result} |
| 4161 |
% The |log_result| procedure inserts the \word{permanent result} at |
| 4162 |
% the current position in the file. If the |antiprompt| is |
| 4163 |
% nonempty then the result is first broken into lines and then |
| 4164 |
% reassembled, however. It also displays the \word{passing result} on |
| 4165 |
% the status line (this has to be done last, since |insertText| |
| 4166 |
% clears the status line). |
| 4167 |
% \begin{tcl} |
| 4168 |
proc eemenu::logWindow::log_result {was_err passing permanent} { |
| 4169 |
if {[string length $permanent]} then { |
| 4170 |
upvar #0 eemenu::logWindow::A A |
| 4171 |
if {[string length $A(antiprompt)]} then { |
| 4172 |
set L [lreplace [split $permanent \n\r] end end] |
| 4173 |
set permanent "[join $L "\n$A(antiprompt)"]\n" |
| 4174 |
} |
| 4175 |
insertText -w $A(winName) "$A(antiprompt)$permanent" |
| 4176 |
} |
| 4177 |
if {[string length $passing]} then {status::msg $passing} |
| 4178 |
} |
| 4179 |
% \end{tcl} |
| 4180 |
% \end{proc} |
| 4181 |
% |
| 4182 |
% \begin{proc}{log_close} |
| 4183 |
% This procedure does nothing. |
| 4184 |
% \begin{tcl} |
| 4185 |
proc eemenu::logWindow::log_close {} {} |
| 4186 |
% \end{tcl} |
| 4187 |
% \end{proc} |
| 4188 |
% |
| 4189 |
% |
| 4190 |
% \section{Default command definitions} |
| 4191 |
% \label{Sec:DefCmdA} |
| 4192 |
% |
| 4193 |
% This section contains some examples of \eemenu\ commands and |
| 4194 |
% it also provides defaults for the |cmdA| array. |
| 4195 |
% |
| 4196 |
% \setnamespace{eemenu} |
| 4197 |
% |
| 4198 |
% \begin{arrayvar}{cmdA} |
| 4199 |
% If this array is already set then there is no need to source the |
| 4200 |
% rest of the file. |
| 4201 |
% \begin{tcl} |
| 4202 |
if {[info exists eemenu::cmdA]} then {return} |
| 4203 |
% \end{tcl} |
| 4204 |
% \end{arrayvar} |
| 4205 |
% |
| 4206 |
% |
| 4207 |
% \begin{arrayentry}{cmdA}{dtx -> internal Tcl} |
| 4208 |
% This is the command that corresponds most closely to that provided |
| 4209 |
% by the old \textsf{dtxload} package. |
| 4210 |
% \begin{tcl} |
| 4211 |
set {eemenu::cmdA(dtx -> internal Tcl)} [list\ |
| 4212 |
% \end{tcl} |
| 4213 |
% By default the command is active and bound to \textsf{Cmd--L} in |
| 4214 |
% \TeX\ mode, but it is not put in the menu. |
| 4215 |
% \begin{tcl} |
| 4216 |
active 1 binding /L<O mode TeX\ |
| 4217 |
in_menu 0\ |
| 4218 |
% \end{tcl} |
| 4219 |
% The extraction method is docstripping. Only code in \texttt{.dtx} |
| 4220 |
% files that is furthermore in a \texttt{tcl} or \texttt{tcl*} |
| 4221 |
% environment is kept. Again, these are the defaults in the |
| 4222 |
% \textsf{dtxload} package. |
| 4223 |
% \begin{tcl} |
| 4224 |
extractor Docstrip extract_extra [list\ |
| 4225 |
filePatL *.dtx sourceEnvsL {tcl tcl*} lookAtEnvs 1\ |
| 4226 |
]\ |
| 4227 |
% \end{tcl} |
| 4228 |
% The command uses |info complete| to test if it has got a complete |
| 4229 |
% command, sends the extracted code to \Alpha's internal \Tcllogo\ |
| 4230 |
% interpreter, and logs the result on the status line. |
| 4231 |
% \begin{tcl} |
| 4232 |
complete "Tcl Info Complete" complete_extra {}\ |
| 4233 |
% |
| 4234 |
evaluator "Internal Tcl" eval_extra {}\ |
| 4235 |
% |
| 4236 |
reporter "Status Line" report_extra {}\ |
| 4237 |
% |
| 4238 |
] |
| 4239 |
% \end{tcl} |
| 4240 |
% Of course, this default setting needs to be saved. |
| 4241 |
% \begin{tcl} |
| 4242 |
prefs::modified {eemenu::cmdA(dtx -> internal Tcl)} |
| 4243 |
% \end{tcl} |
| 4244 |
% \end{arrayentry} |
| 4245 |
% |
| 4246 |
% |
| 4247 |
% \begin{arrayentry}{cmdA}{dtx -> remote Tcl} |
| 4248 |
% This is a command that I have lately found to be increasingly useful. |
| 4249 |
% The functionality was provided in the \textsf{dtxload} package, but |
| 4250 |
% it was always slightly awkward as it was not a distinct command. |
| 4251 |
% Instead the |evaluateRemotely| variable was used as a selector |
| 4252 |
% between this and the previous command. |
| 4253 |
% |
| 4254 |
% Since these two commands are anyway quite similar, I'll copy |
| 4255 |
% settings from the above, only changing those that are different. |
| 4256 |
% \begin{tcl} |
| 4257 |
catch {unset A} |
| 4258 |
array set A [set {eemenu::cmdA(dtx -> internal Tcl)}] |
| 4259 |
% \end{tcl} |
| 4260 |
% Since keys combinations are sort of in short supply, this command |
| 4261 |
% is by default inactive but has the same binding and mode as its |
| 4262 |
% \textsf{internal~Tcl} counterpart. This means that if one of these |
| 4263 |
% commands is activated then the other is automatically deactivated |
| 4264 |
% and so it is anyway easy to switch between them. I also put this |
| 4265 |
% remote \Tcllogo\ command in the menu. |
| 4266 |
% \begin{tcl} |
| 4267 |
set A(active) 0 |
| 4268 |
set A(in_menu) 1 |
| 4269 |
% \end{tcl} |
| 4270 |
% |
| 4271 |
% Communication with remote interpreters is a messy business, due to |
| 4272 |
% the many technical details one has do deal with. It is also very |
| 4273 |
% platform-dependent. The Mac\,OS settings are however not too |
| 4274 |
% complicated, much thanks to \TclAE. |
| 4275 |
% \changes{v\,0.3}{2003/06/01}{Corrected condition used for selecting |
| 4276 |
% remote evaluation method. (LH)} |
| 4277 |
% \begin{tcl} |
| 4278 |
if {[info exists eemenu::evaluate(doScriptAE)]} then { |
| 4279 |
set A(evaluator) "Do Script AE" |
| 4280 |
set A(eval_extra)\ |
| 4281 |
[list targetApp '${tclshSig}' joinString 0 replyQ 1] |
| 4282 |
} \ |
| 4283 |
% \end{tcl} |
| 4284 |
% |
| 4285 |
% The Windoze settings are the most complicated. One reason for this |
| 4286 |
% is that |dde execute| does not return the result of the script, so |
| 4287 |
% that a separate call is needed for this. |
| 4288 |
% \begin{tcl} |
| 4289 |
elseif {[info exists eemenu::evaluate(windozeDDE)]} then { |
| 4290 |
set A(evaluator) "Windoze DDE" |
| 4291 |
set A(eval_extra) [list\ |
| 4292 |
% |
| 4293 |
service TclEval target Tcl_1 launchCmd\ |
| 4294 |
{exec $tclshSig [file join $HOME Tools winRemoteShell.tcl] &}\ |
| 4295 |
% |
| 4296 |
joinString 0 prefix "catch \{" suffix "\} alpha_result"\ |
| 4297 |
request alpha_result] |
| 4298 |
} \ |
| 4299 |
% \end{tcl} |
| 4300 |
% |
| 4301 |
% Finally, there are the settings for |send|, which are used on all |
| 4302 |
% other platforms. |
| 4303 |
% \begin{tcl} |
| 4304 |
else { |
| 4305 |
set A(evaluator) "Tk Send" |
| 4306 |
set A(eval_extra) [list target wish joinString 0 replyQ 1] |
| 4307 |
} |
| 4308 |
% \end{tcl} |
| 4309 |
% Then all that remains is to store the settings into the |cmdA| array. |
| 4310 |
% \begin{tcl} |
| 4311 |
set {eemenu::cmdA(dtx -> remote Tcl)} [array get A] |
| 4312 |
prefs::modified {eemenu::cmdA(dtx -> remote Tcl)} |
| 4313 |
unset A |
| 4314 |
% \end{tcl} |
| 4315 |
% \end{arrayentry} |
| 4316 |
% |
| 4317 |
% \begin{arrayentry}{cmdA}{Tcl example in AIDA} |
| 4318 |
% AIDA probably isn't that well known, but in brief it is an |
| 4319 |
% experimental source format for \Alpha\ documentation, which can |
| 4320 |
% be converted to plain text, \LaTeX, HTML, and some other formats too. |
| 4321 |
% Verbatim text lines (as needed for code examples) can of course be |
| 4322 |
% included expressed in AIDA; the required markup is mainly that each |
| 4323 |
% such line begins with the two characters \verb"(|". Such code can |
| 4324 |
% easily be extracted using the regexp extractor. |
| 4325 |
% |
| 4326 |
% This code is no longer included, since AIDA isn't much used anymore. |
| 4327 |
% \begin{tcl} |
| 4328 |
%<*aidacode> |
| 4329 |
set {eemenu::cmdA(Tcl example in AIDA)} [list\ |
| 4330 |
% |
| 4331 |
extractor Regexp extract_extra [list\ |
| 4332 |
% \end{tcl} |
| 4333 |
% The filter should get the lines matching the expression, i.e., it |
| 4334 |
% should work in \texttt{grep} mode, and the characters that are |
| 4335 |
% matched should be removed. |
| 4336 |
% \begin{tcl} |
| 4337 |
filter_mode grep filterRE {^\(\|} searchRE {^\(\|} replaceRE {}]\ |
| 4338 |
% \end{tcl} |
| 4339 |
% Evaluation is internally in \Alpha, and the completion test can use |
| 4340 |
% |info complete|. |
| 4341 |
% \begin{tcl} |
| 4342 |
complete "Tcl Info Complete" complete_extra {}\ |
| 4343 |
% |
| 4344 |
evaluator "Internal Tcl" eval_extra {}\ |
| 4345 |
% \end{tcl} |
| 4346 |
% Then there's the matter of how to report the result. Since that |
| 4347 |
% hasn't been used yet, it seems a good idea to try to use a log |
| 4348 |
% window here. |
| 4349 |
% \begin{tcl} |
| 4350 |
reporter "Log Window" report_extra {winName {AIDA example log}\ |
| 4351 |
winMode Tcl prompt {% } antiprompt {}}\ |
| 4352 |
% \end{tcl} |
| 4353 |
% Finally there's the matter of the binding and the menu. There isn't |
| 4354 |
% anything new here, except that the binding is only made active if |
| 4355 |
% \texttt{AIDA} mode is installed (since modes not installed will |
| 4356 |
% sometimes be interpreted as |<none>|, i.e., global). |
| 4357 |
% \begin{tcl} |
| 4358 |
active [mode::exists AIDA] binding /L<O mode AIDA in_menu 1] |
| 4359 |
prefs::modified {eemenu::cmdA(Tcl example in AIDA)} |
| 4360 |
%</aidacode> |
| 4361 |
% \end{tcl} |
| 4362 |
% \end{arrayentry} |
| 4363 |
% |
| 4364 |
% \begin{arrayentry}{cmdA}{Tcl Wiki} |
| 4365 |
% When editing a page on the \Tcllogo'ers Wiki~\cite{TclWiki} or the |
| 4366 |
% \AlphaTcl\ Wiki~\cite{AlphaTclWiki}, one occasionally finds the need |
| 4367 |
% to test some piece of \Tcllogo\ code on that page. This is down to a |
| 4368 |
% single keypress with the following command, that extracts lines of |
| 4369 |
% verbatim text from a Wiki page and feeds them to the internal |
| 4370 |
% interpreter. |
| 4371 |
% |
| 4372 |
% The syntax of verbatim lines on the \Tcllogo'ers Wiki is |
| 4373 |
% basically ``any line that starts with a space'', but unfortunately |
| 4374 |
% there are a few exceptions. The equivalents of \LaTeX\ \verb|\item|s |
| 4375 |
% for \texttt{itemize} or \texttt{enumerate} are coded as lines that |
| 4376 |
% begin with three spaces, a \texttt{*} or \meta{digit}\texttt{.} |
| 4377 |
% respectively, and another space. The equivalents of \LaTeX\ |
| 4378 |
% \verb|\item|s for \texttt{description} are coded as lines that |
| 4379 |
% begin with \emph{at least} three spaces, some other characters, a |
| 4380 |
% colon, and another three spaces (exactly). It is possible to write a |
| 4381 |
% regular expression to filter out such lines. |
| 4382 |
% \begin{tcl} |
| 4383 |
set {eemenu::cmdA(Tcl Wiki)} [list\ |
| 4384 |
% |
| 4385 |
extractor Regexp extract_extra [list\ |
| 4386 |
% \end{tcl} |
| 4387 |
% The filter works in \texttt{anti-grep} mode, and has to filter out |
| 4388 |
% four different types of non-code lines. There is however no need |
| 4389 |
% for further substitutions on the code lines. |
| 4390 |
% \begin{tcl} |
| 4391 |
filter_mode anti-grep searchRE {} replaceRE {}\ |
| 4392 |
filterRE {^[^ ]|^ (\*|[0-9]\.) |^ .+: [^ ]} ]\ |
| 4393 |
% \end{tcl} |
| 4394 |
% Evaluation is internally in \Alpha, and the completion test can use |
| 4395 |
% |info complete|. |
| 4396 |
% \begin{tcl} |
| 4397 |
complete "Tcl Info Complete" complete_extra {}\ |
| 4398 |
% |
| 4399 |
evaluator "Internal Tcl" eval_extra {}\ |
| 4400 |
% \end{tcl} |
| 4401 |
% Then there's the matter of how to report the result. Since that |
| 4402 |
% hasn't been used yet, it seems a good idea to try to use a log |
| 4403 |
% window here. |
| 4404 |
% \begin{tcl} |
| 4405 |
reporter "Log Window" report_extra {winName {Wiki code log}\ |
| 4406 |
winMode Tcl prompt {% } antiprompt {}}\ |
| 4407 |
% \end{tcl} |
| 4408 |
% Finally there's the matter of the binding and the menu. There isn't |
| 4409 |
% anything new here, except that the binding is only made active if |
| 4410 |
% \texttt{Wiki} mode is installed (since modes not installed will |
| 4411 |
% sometimes be interpreted as |<none>|, i.e., global). |
| 4412 |
% \begin{tcl} |
| 4413 |
mode Wiki active [mode::exists Wiki] binding /L<O in_menu 1] |
| 4414 |
prefs::modified {eemenu::cmdA(Tcl Wiki)} |
| 4415 |
% \end{tcl} |
| 4416 |
% \end{arrayentry} |
| 4417 |
% |
| 4418 |
% Finally, let's try something which isn't \Tcllogo. |
| 4419 |
% |
| 4420 |
% \begin{arrayentry}{cmdA}{Mathematica} |
| 4421 |
% It is a fairly small modification to make a command which sends |
| 4422 |
% DoScript AEs to Mathematica instead of Wish. There's probably a way |
| 4423 |
% to do this using |dde| too, but I don't know what that could be. |
| 4424 |
% |
| 4425 |
% Since Mathematica code presumably concerns rather mathematical |
| 4426 |
% problems, the comments to the code is likely to contain fairly |
| 4427 |
% advanced mathematical formulae. This makes the \texttt{.dtx} |
| 4428 |
% format an interesting choice for source format, and hence I choose |
| 4429 |
% to use docstripping as extraction method. As there is no special |
| 4430 |
% environment for Mathematica code, the source environments are the |
| 4431 |
% generic \texttt{macrocode} and \texttt{macrocode*}. |
| 4432 |
% \begin{tcl} |
| 4433 |
set eemenu::cmdA(Mathematica) [list\ |
| 4434 |
% |
| 4435 |
extractor Docstrip extract_extra [list\ |
| 4436 |
filePatL *.dtx sourceEnvsL {macrocode macrocode*} lookAtEnvs 1\ |
| 4437 |
]\ |
| 4438 |
% \end{tcl} |
| 4439 |
% The extracted code is sent in a DoScript AppleEvent to the |
| 4440 |
% Mathematica kernel. Unfortunately the kernel doesn't seem to |
| 4441 |
% produce any result, so we'll have to leave it at that. Since there |
| 4442 |
% is no convenient way of testing whether something is a complete |
| 4443 |
% command in this case, all code from the entire selection is sent in |
| 4444 |
% one event. |
| 4445 |
% \begin{tcl} |
| 4446 |
evaluator "Do Script AE" eval_extra\ |
| 4447 |
[list targetApp 'Math' joinString 1 replyQ 0]\ |
| 4448 |
% |
| 4449 |
complete "Entire Selection" complete_extra {}\ |
| 4450 |
% |
| 4451 |
reporter "Status Line" report_extra {}\ |
| 4452 |
% \end{tcl} |
| 4453 |
% The binding and menu settings are the same as for the remote |
| 4454 |
% \Tcllogo\ command. |
| 4455 |
% \begin{tcl} |
| 4456 |
active 0 binding /L<O mode TeX in_menu 0] |
| 4457 |
% \end{tcl} |
| 4458 |
% Of course, this default setting needs to be saved. |
| 4459 |
% \begin{tcl} |
| 4460 |
prefs::modified {eemenu::cmdA(Mathematica)} |
| 4461 |
% \end{tcl} |
| 4462 |
% \end{arrayentry} |
| 4463 |
% |
| 4464 |
% |
| 4465 |
% \begin{thebibliography}{9} |
| 4466 |
% \bibitem{TclWiki} |
| 4467 |
% The \Tcllogo'ers Wiki, |
| 4468 |
% \href{http://purl.org/tcl/wiki/}{\textsc{http:}/\slash |
| 4469 |
% \texttt{purl.org}\slash \texttt{tcl}\slash \texttt{wiki}/} |
| 4470 |
% \bibitem{AlphaTclWiki} |
| 4471 |
% \AlphaTcl\ Wiki, \href{http://alphatcl.sourceforge.net/wikit/} |
| 4472 |
% {\textsc{http:}/\slash \texttt{alphatcl.sourceforge.net}\slash |
| 4473 |
% \texttt{wikit}/} |
| 4474 |
% \end{thebibliography} |
| 4475 |
% |
| 4476 |
% |
| 4477 |
\endinput |