Emacs: 智能感知和操作光标处的语法对象

expand-region我用过一下。感觉还是不太直接。

er/mark-xxx应该也可以做定制。我没有太深度使用哈。

thing-edit的函数就比较直接了,连选中都不需要。

thing-replace-xxx是我后面我加的,可以看下 这里

实际使用起来是比较方便的。可以尝试一下 :slight_smile:

不一样,我不强调一层层扩展。

我只希望想要复制的时候直接复制

不要选半天,麻烦

拷贝时高亮区域很方便,如果要美观和统一,建议直接用内置的pulse,和 xref 效果一样。当然目前这样也是可用的。

thing-editexpand-region思路不同,thing-edit 直接一些。不过如果不用one-key之类的按键用起来也挺麻烦。

@ moyotar 我目前用 easy-kill 配合 smart-region (依赖于 expand-region ),效果还不错。正在试用 thing-edit

1 个赞

这两天试用了thing-edit,感觉还是挺方便的。按照 emacs 习惯,确实应该叫 copy kill yank。Anyway,个人做了一点小小的扩展:如果选中 region 直接 copy,没有 copy 整行内容。感觉这种casse还是挺普遍的。

  (defun thing-copy-region-or-line (&optional kill-conditional)
    "Copy content of the current region or line.
If `KILL-CONDITIONAL' is non-nil, kill object,
otherwise copy object."
    (interactive)
    (save-excursion
      (let* ((active (region-active-p))
             (pos (or (and active (region-beginning))
                      (line-beginning-position)))
             (pos-end (or (and active (region-end))
                          (line-end-position))))
        (thing-edit-internal pos pos-end kill-conditional))))

  (defun thing-cut-region-or-line ()
    "Cut content of the current region or line."
    (interactive)
    (thing-copy-region-or-line t))

  (defun thing-replace-region-or-line ()
    "Replace the current region or line with the content."
    (interactive)
    (thing-replace 'region))

之前我一直在使用easy-kill,感觉两者功能有重合也能互补。比如easky-kill提供了快速拷贝当前 buffer file name 的功能,还有好用的easy-mark

另外,研究过程中发现了omni-kill,功能和实现和thing-edit都基本类似,只是功能少些。这算是重复造轮子不 :joy:

1 个赞

可以提交pr

这算是他重复轮子吧,thing-edit.el十年前就写了

新版已经用 pulse 替代了

对啊,大佬没有发布出来,他就开始重复造轮子了 :joy:

这么快就加上 pulse 了 :grinning:

color-rg.el 也换成 pulse 了, 哈哈哈

Add `thing-*-region-or-line' functions. · manateelazycat/thing-edit@21c1bd1 · GitHub 你的函数我内置了.

OK, 谢谢! 这样我就可以去掉自己的配置了,没有提交 PR,论坛提供也算contribution 了 :grinning: 不过,我没有过多测试哈,你要多 review 下啦

replace 函数我改了一下

嗯,good。有没有考虑增加copy 整个 buffer的函数?

我一般用 (mark-whole-buffer), 主要是我用的很少.

不过我不排斥你发PR, 哈哈哈哈.

这个简单呀,review 下吧,哈哈哈

  (defun thing-copy-whole-buffer (&optional kill-conditional)
    "Copy content of the current buffer.
If `KILL-CONDITIONAL' is non-nil, kill object,
otherwise copy object."
    (interactive)
    (save-excursion
      (thing-edit-internal (point-min) (point-max) kill-conditional)))

  (defun thing-cut-whole-buffer ()
    "Cut content of the current buffer."
    (interactive)
    (thing-copy-whole-buffer t))

  (defun thing-replace-whole-buffer ()
    "Replace the current buffer with the content."
    (interactive)
    (thing-replace 'buffer))

突然想到一个问题,thing-edit 似乎没有考虑 narrow 的 case,当然绝大多数情况是够用了。另外对于内容很多的情况下 minibuffer 显示就不大好了。

minibuffer 你有啥建议? 我没想到更好方案, 主要觉得不移动光标拷贝就已经让我自己很爽了.

narrow 的情况其实不用去考虑, 没人抱怨就是因为没人那么用, 哈哈哈哈

很多工具浏览 kill-ring的时候超出限值都会截断,比如:counsel-yank-pop

我觉得可以参考。 甚至只是给个简单的 message ,如:Copy the current symbol,应该足够用了。

Copy 可以这样做, 已经有高亮提醒了, cut和replace如果不提醒有时候还是不方便.

我就喜欢你这种一言不合就飚代码的老司机, 已经合并了: Add `thing-*-whole-buffer' functions. · manateelazycat/thing-edit@6b35788 · GitHub

干这行太久的老毛病,前提是自己略知一二才行呀 :joy:

嗯,Cut、Replace 提醒我没有仔细考虑。话说没有上 melpa,更新起来还是挺麻烦呀,我是不是该考虑下straight之类的呢……

submodule不错啊

别用straight, 没有shadow clone下载半年