SAS 增强编辑器:提交代码块而不手动突出显示 [英] SAS Enhanced Editor: Submitting code block without manually highlighting

查看:19
本文介绍了SAS 增强编辑器:提交代码块而不手动突出显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很少需要提交整个 .sas 文件.相反,我一次提交一个步骤.这意味着我不断地突出代码.

Very rarely do I ever need to submit an entire .sas file. Instead, I submit steps one at a time. This means I am constantly highlighting code.

问题:有没有办法让 SAS 提交代码块而不手动突出显示它?

Question: Is there a way to have SAS submit a block of code without manually highlighting it?

临时工作:

Emacs ESS 有评估本段和步骤"命令C-c C-p.一种解决方案是使用 ESS 而不是增强型编辑器.但是,我正在开发适用于 Windows 的 SAS,它目前似乎没有与 ESS 的交互功能.

Emacs ESS has the "Evaluate this paragraph and step" command C-c C-p. One solution would be to use ESS instead of the Enhanced Editor. However, I am working on SAS for Windows which does not currently appear to have interactive functionality with ESS.

SUBTOP 命令,可用于提交前 n 行代码.但是,SUBTOP 似乎无法在整个文档中的任意位置提交代码.

There is the SUBTOP command which can be used to submit the first n lines of code. However, SUBTOP does not seem to be able to submit code at an arbitrary position within the entire document.

用空行分隔步骤似乎是 SAS 标准做法.这意味着代码块可以定义为两个非连续空行之间的文本.

It appears to be SAS standard practice to separate steps by a blank line. This means a block of code may be defined as the text between two non-consecutive blank lines.

推荐答案

简单的回答是不,没有办法在 SAS 中使用单个按键提交代码块.

The short answer is no, there is no way to submit a code block in SAS using a single keystroke.

让我解释一下原因.

文本区域由光标、点和标记两个方面决定.Point 是光标相对于文件开头的当前位置.Mark 是一个包含光标可能位置的变量.区域是点和标记之间的文本.

A region of text is determined by two aspects of the cursor, point and mark. Point is the current position of the cursor relative to the start of the file. Mark is a variable containing a possible position of the cursor. Region is the text between the point and the mark.

提交代码块可以看作是一个两步过程:

Submitting a code block can be viewed as a two step process:

  1. 选择一个地区.
  2. 将所选区域提交给编译器.

要将此过程绑定到单个键,需要能够使用代码选择区域.流程会如下所示.

To bind this process to a single key requires being able to select a region using code. The process would go something as follows.

  1. 创建一个命令样式的宏,它首先选择一个区域,可能使用 FIND 命令 定位一个块(搜索回车、换行、运行";声明等).
  2. 设置标记.
  3. 将点移动到区域的开头.
  4. 选择地区.
  5. 使用 SUBMITGSUBMITEND 命令执行区域.
  6. 编译宏并使用 KEYS 菜单将其绑定到功能键.
  1. Create a command-style macro which first selects a region, probably using the FIND command to locate the end of a block (searching for a carriage return, line feed, "run;" statement, etc.).
  2. Set the mark.
  3. Move the point to the start of the region.
  4. Select the region.
  5. Execute the region using the SUBMIT, GSUBMIT, or END commands.
  6. Compile the macro and bind it to a function key using the KEYS menu.

这有两个问题.

首先,没有办法在增强编辑器 (EE) 中设置标记使用代码.如果没有标记,则无法定义区域,上述过程将失败.@guest 引用的 MARK 命令仅适用于程序编辑器.要查看此内容,请尝试按 Ctrl+M 或从 EE 的命令行发出 MARK 命令.您将收到以下消息:

First, there is no way to set the mark in the Enhanced Editor (EE) using code. Without a mark, a region cannot be defined and the process described above fails. The MARK command referred to by @guest applies only to the Program Editor. To see this, try pressing Ctrl+M or issuing the MARK command from the command line in the EE. You will receive the following message:

ERROR: The MARK command is not supported by the Enhanced Editor. 

其次,不清楚如何使用代码选择区域.所有这些的文档是不同且不完整的.没有办法设置标记,我没有花太多时间研究如何选择.

Second, it is unclear how to select a region using code. The documentation for all of this is disparate and incomplete. Without a way to set the mark, I did not spend too much time investigating how to select.

然而,令人着迷的是使用 键盘宏.这与 MARK 命令有何不同或为何不同,我无法理解.也可以选择区域.虽然似乎缺少设置标记和选择的代码命令使我们无法创建单次击键提交,但键盘宏使我们能够开发两种击键方法.

Tantilizingly, however, is the ability to set the mark in the EE using a keyboard macro. How or why this differs from the MARK command is beyond me. It is also possible to select a region. While a seeming lack of code commands to set mark and select prevents us from creating a single keystroke submit, keyboard macros enable us to develop a two keystoke approach.

工具>选项>偏好>结果 我已经检查了查看生成的结果".这会在提交代码后强制结果窗口显示在前台.

Under Tools > Options > Preferences > Results I have checked "View results as they are generated". This forces the results window to take the foreground after code is submitted.

在 KEYS 屏幕中,我有以下内容:

In the KEYS screen, I have the following:

Key  Definition
---  ----------
F3   clear log; end; log; wpgm;
F4   clear log; end;

当我按下 F3

  • 日志被清除(clear log;)
  • 所选区域已提交(end;)
  • 选择日志窗口(log;)
  • 选择了最近的程序窗口 (wpgm;)

这意味着结果不会立即显示给我,尽管上面设置了首选项设置.如果我想查看结果,我改为按 F4.这会清除日志并提交代码,但不会选择任何其他窗口.

This means the results are not immediately displayed to me, depsite the Preferences setting set above. If I want to see the results, I instead press F4. This clears the log and submits the code, but does not select any other windows.

要打开 KEYS 屏幕,请在 EE 界面左上角的命令行中键入 KEYS 或提交 dm 'KEYS';.对 KEYS 菜单所做的更改必须先保存才能生效.

To open the KEYS screen, either type KEYS into the command line in the top left corner of the EE interface or submit dm 'KEYS';. Changes to the KEYS menu must first be saved before they take effect.

关于创建键盘宏的说明.

创建一个执行以下操作的键盘宏.

Create a keyboard macro which does the following.

  1. 将光标移至行首
  2. 将选择范围扩展到行尾

我已将此绑定到 Ctrl+Enter.然后我可以使用 Ctrl+Enter > 执行一行代码.F3.

I have this bound to Ctrl+Enter. I may then execute a line of code using Ctrl+Enter > F3.

这种方法需要启用可折叠的代码部分.为此,请转到 Tools >选项>增强编辑器 >常规并选中折叠代码部分"复选框.

This approach requires collapsible code sections be enabled. To do this, goto Tools > Options > Enhanced Editor > General and check the 'Collapse code sections' check boxes.

在键盘宏中,

  1. 分配一个命令来标记当前位置"(Ctrl+Space).
  2. 分配'切换扩展当前行' (Alt+P)
  3. 分配从标记扩展选择"(Alt+L)

完成此操作后,将光标放在折叠块的末尾,例如 run; 语句中的分号右侧.执行序列:

Once this has been done, place your cursor at the end of a folding block, such as to the right of the semi-colon in a run; statment. Execute the sequence:

  1. 标记当前位置
  2. 切换展开当​​前行
  3. 切换展开当​​前行
  4. 从标记扩展选择

切换展开当​​前行"的副作用是,当折叠代码块时,点会移动到折叠块的开头.由于我们在块的末尾设置了标记,这允许我们定义和选择一个区域.

A side effect of 'Toggle expand current line' is that when a code block is folded, the point moves to the beginning of the folding block. Since we set the mark at the end of the block, this allows us to define and select a region.

就我分配的键而言,这是 Ctrl+Space >Alt+P >Alt+P >Alt+L.请注意,Alt 可能会在此序列的最后三个步骤中保持按下状态,使其变为 Ctrl+Space >Alt (P-P-L).因此,要使用键盘手动提交折叠块,请将光标放在块的末尾并发出 Ctrl+Space >Alt (P-P-L) >F3.

In terms of the keys I have assigned, this is Ctrl+Space > Alt+P > Alt+P > Alt+L. Note that Alt may remain pressed during the last three steps of this sequence so that it becomes Ctrl+Space > Alt (P-P-L). Therefore, to manually submit a folding block using the keyboard, place the cursor at the end of a block and issue Ctrl+Space > Alt (P-P-L) > F3.

此自动过程依赖于上一节中描述的切换扩展当前行"键盘宏的副作用.手动代码折叠/选择过程使用搜索功能自动完成.

This automatic process relies on a side-effect of the 'Toggle expand current line' keyboard macro which is described in the previous section. The manual code folding/selecting process is automated using the search function.

整体流程可以分为两部分:

The overall process can be seen in two parts:

  1. 找到折叠块的末端.
  2. 选择折叠块.

折叠块的定义如下.

块的开始:

  • proc <名称/选项>;
  • 数据<名称/选项>;
  • %macro <name/options>;

块结束:

  • 运行;
  • 退出;
  • %mend;

分号在 EE 中切换块边界.EE 天真地寻找关键字对.因此,即使对编译器来说是无意义的,也可以定义一个 data-%mend 折叠块.

The semi-colon toggles the block boundary in the EE. The EE naively looks for keyword pairs. So, even though it's nonsense to the compiler, it is possible to define a data-%mend folding block.

下面给出了每个部分需要通过键盘宏发出的命令.

The following gives the commands which need to be issued by a keyboard macro for each part.

我.查找块结束语句

  1. 将光标移至行首(这可确保折叠块边界包含在第 3 步中的前向搜索集中).
  2. 重置搜索.
  3. 将搜索方向设置为前进.
  4. 将搜索设置为不区分大小写.
  5. 将搜索设置为忽略评论中的文字.
  6. 将搜索设置为代码.
  7. 打开正则表达式模式进行搜索.
  8. 将搜索设置为字符串<[rqm][ue][ni][dt]*>;
  9. 使用当前设置查找下一个事件.
  10. 向右移动光标(找到块结尾语句时,整个单词都会突出显示.向右移动光标会将点置于折叠块的末尾,分号右侧.).

二.选择折叠块

  1. 标记当前位置.
  2. 切换扩展当前行.(折叠具有将光标移动到块开头的副作用的部分).
  3. 切换扩展当前行.(展开选择以允许突出显示.光标保持在块的开头).
  4. 将选择范围扩展到标记.

我将此序列绑定到 Ctrl+Shift+Enter.

请注意,宏中更改的搜索设置不会全局扩展.也就是说,如果您点击 Ctrl+F 并取消选中正则表达式搜索",如果在运行此宏后再次打开 Ctrl+F,您将看到Regular表达式搜索'保持未选中状态.

Note that the search settings altered in the macro do not extend globally. That is, if you hit Ctrl+F and have 'Regular expression search' unchecked, if you again open Ctrl+F after running this macro, you will see that 'Regular expression search' remains unchecked.

让我解释一下第 8 步中的正则表达式,因为它不是很明显.

Let me explain the regular expression in Step 8 because it is not immediately obvious.

Ctrl+F 对话框不使用 Perl 正则表达式.它使用了其他东西,可能是在 Perl 集成到 SAS 之前出现的任何正则表达式语法.要查看可用的选项,请单击查找文本:"旁边的箭头.查找对话框中的文本框.我们使用的选项如下:

The Ctrl+F dialog does not use Perl Regular Expressions. It uses something else, probably whatever regex syntax came before Perl was integreated into SAS. To see what options are available, click on the arrow beside the "Find text:" text box in the Find dialog. The options we use are given below:

  • < 匹配单词的开头
  • > 匹配词尾
  • [] 匹配一组字符(通过异或)
  • * 强制前面的字符出现 0 次或多次
  • < matches the beginning of a word
  • > matches the end of a word
  • [] matches a set of characters (via exclusive OR)
  • * forces 0 or more occurances of the preceeding character(s)

正则表达式<[rqm][ue][ni][dt]*>;表示单词必须以r开头,<代码>qm.第二个字符只能是 ue.第三个字符只能是 ni.如果存在第四个字符,则它必须是 dt.最后一个字符必须是 ;.因此,只会找到关键字 run;quit;mend;.包含完整或部分匹配的单词,例如 ammendtreatment,将被跳过.

The regular expression <[rqm][ue][ni][dt]*>; means that the word must start with r, q, or m. The second character can only be u or e. The third character can only be n or i. If a fourth character exists, it must either be d or t. The last character must be ;. Therefore, only the keywords run;, quit; and mend; will be found. Words containg full or partial matches, such as ammend or treatment, are skipped.

这种方法的缺点

  1. 不支持 run;quit;mend; 以外的关键字.
  2. 不支持折叠块内的折叠块.这种方法并不聪明",因为它无法辨别哪些关键字对定义了外部块.
  3. 不支持喜欢将宏名称放在 mend 语句中的用户.由于正则表达式的末尾需要分号,因此将跳过 %mend MacroName; 形式的语句.
  1. Keywords other than run;, quit; and mend; are not supported.
  2. Folding blocks inside folding blocks are not supported. This method is not 'smart' in that it cannot discern which keyword pairs define the outer block.
  3. People who like to put the name of their macro in the mend statement are not supported. Since the regex expression requires a semi-colon at the end, a statement of the form %mend MacroName; will be skipped over.


根据几个月的研究,这似乎是可以开发的最完整的解决方案.所需的 lynch pin(s) 是基于代码的设置标记和在增强编辑器中选择区域的能力.如果有人知道这样做的方法,请让其他人知道,以便有人可以实施本答案第一部分中概述的单键提交过程.


Based on months of research, this appears to be as complete a solution as can be developed. The lynch pin(s) needed are a code based ability to set mark and to select a region within the Enhanced Editor. If anyone knows of a way to do this, please let others know so that someone may implement the single-key-submit process outlined in the first part of this answer.

这篇关于SAS 增强编辑器:提交代码块而不手动突出显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆