以编程方式选择一个区域 [英] Programmatically selecting a region

查看:119
本文介绍了以编程方式选择一个区域的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想通过点击 C-Space +移动箭头键,但在elisp中执行相同的操作。

I want to perform the same action that one does by hitting C-Space + moving the arrow keys, but in elisp.

没有找到正确的功能(如果他们只是在逻辑上分组在命名空间或以某种方式标记...)。

Failing to find the right function (if they just were logically grouped in namespaces or somehow tagged...). Which one is it?

推荐答案

您可以使用 Ch k 键将键击翻译成elisp键

你会注意到设置标记 set-mark-command 的elisp函数,需要一个非可选参数。 Emacs使用特殊的 交互式 函数允许使用参数自然编写elisp函数。这允许它们在其他elisp程序中是通用且易于重用的,同时仍然可以直接从按键中调用。它还具有内置的一些 Cu 前缀逻辑。

You'll notice the elisp function for setting the mark set-mark-command, takes one non-optional argument. Emacs uses the special interactive function to allow elisp functions to be written naturally with arguments. This allows them to be generic and easy to reuse in other elisp programs, while still possible to invoke directly from a keystroke. It also has some of the C-u prefix logic built-in.

set-mark-command的情况下,其第一个函数是(交互式P),这意味着从键盘调用时,前缀作为参数传入。您可以直接在elisp中进行模拟:

In the case of set-mark-command, its first function is (interactive "P"), which means the prefix is passed in as an argument when called from the keyboard. You can simulate this directly in elisp with:

(set-mark-command nil)

例如,要在elisp中选择当前行:

For example, to select the current line in elisp:

(defun my-select-current-line ()
  (interactive)
  (move-beginning-of-line nil)
  (set-mark-command nil)
  (move-end-of-line nil)
  (setq deactivate-mark nil))

请注意,您必须告诉emacs在最后才能激活该标记,否则该地区将不会保持突出显示(尽管点和标记将是您离开的地方)。

Note you have to tell emacs to leave the mark active at the end or else the region won't remain highlighted (although the point and mark will be where you left them).

这篇关于以编程方式选择一个区域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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