Emacs builtin mode 功能介绍

不习惯use-package,我的配置如下,但是enter、escape并没有打到预期效果,是配置写错了吗?

(when (> emacs-major-version 26)
  (setq isearch-lazy-count t)
  (setq lazy-count-prefix-format "%s/%s ")
  (setq lazy-highlight-cleanup nil)
  )
(defvar my/isearch--direction nil)
(define-advice isearch-exit (:after nil)
  (setq-local my/isearch--direction nil))
(define-advice isearch-repeat-forward (:after (_))
  (setq-local my/isearch--direction 'forward))
(define-advice isearch-repeat-backward (:after (_))
  (setq-local my/isearch--direction 'backward))
(defun my/isearch-repeat (&optional arg)
  (interactive "P")
  (isearch-repeat my/isearch--direction arg))
(define-key isearch-mode-map (kbd "RET") 'my/isearch-repeat)
(define-key isearch-mode-map (kbd "ESC") #'isearch-exit)
(define-key isearch-mode-map [remap isearch-delete-char] 'isearch-del-char) ;

环境:Windows 10原生 GNU Emacs 28.2

试一下 global-goto-address-mode

1 个赞

真的是要global

请问你这个没有达到预期效果具体是什么?不清楚很难解答啊。

就是按enter并没有查找下一处,而是换行,同样esc也没有反应。

RET 改成 <return> ,试一下把 ESC 改成 <esc>

改成 <return><esc>确实有效了。还有两个小问题:

  1. 按esc退出查找后,查找词仍是高亮的,必须再按C-s进入查找模式才恢复;

  2. 进入正向查找后,按什么键可以反向查找?

因为你设置了 (setq lazy-highlight-cleanup nil)

根据代码的意思是你可以选择不断按 C-r 反查,或者按一次 C-r 后不断按 Enter 反查。

1 个赞

今天看视频的时候 https://youtu.be/TJrAkCyH6Dk?si=ar_OuixmgLieCTEL&t=379 学到几个命令 ,(indent-rigidly) 默认在C-x Tab 上,可以实现vim 的 <> 指令,用于 将选中的内容块 左右移动,操作步骤是 C-x Tab 之后 按左右键移动,或Shift+左右键根据缩进层级左右移动。

5 个赞

delim-col.el - helps to prettify columns in a text region or rectangle

Here is an example of columns:

horse	apple	bus
dog	pineapple	car	EXTRA
porcupine	strawberry	airplane

Doing the following settings:

(setq delimit-columns-str-before "[ ")
(setq delimit-columns-str-after " ]")
(setq delimit-columns-str-separator ", ")
(setq delimit-columns-separator "\t")

Selecting the lines above and typing:

M-x delimit-columns-region

It results:

[ horse    , apple     , bus     ,       ]
[ dog      , pineapple , car     , EXTRA ]
[ porcupine, strawberry, airplane,       ]

delim-col.el 的注释里包含更多可能的配置,可以作为 align-regexp 的补充。

3 个赞

看到一个接合 re-builderquery-replace-regexp 实现 在编辑regexp 时 可以在buffer 中可视化的看到哪部分能匹配上regexp (这是re-builder)的原生功能), 他通过将re-builder 与query-replace-regexp 接合后 达到 编辑完 regexp 并 按下return 后,输入 替换的结果,直接执行query-replace-regexp

原文在这: Bridging Islands in Emacs: re-builder and query-replace-regexp | Karthinks

https://www.reddit.com/r/emacs/comments/1dyn3zy/does_emacs_have_this_functionality/ 在他的基础上略作修改。1 是支持最新版的emacs ,2在minibuffer 中提醒用法:“Return:Query Replace,C-cC-c:quit”

(defvar my/re-builder-positions nil
  "Store point and region bounds before calling re-builder")
(defun reb-replace-regexp (&optional delimited)
  "Run `query-replace-regexp' with the contents of re-builder. With
non-nil optional argument DELIMITED, only replace matches
surrounded by word boundaries."
  (interactive "P")
  (reb-update-regexp)
  (let* ((re (reb-target-value 'reb-regexp))
         (replacement (query-replace-read-to
                       re
                       (concat "Query replace"
                               (if current-prefix-arg
                                   (if (eq current-prefix-arg '-) " backward" " word")
                                 "")
                               " regexp"
                               (if (with-selected-window reb-target-window
                                     (region-active-p)) " in region" ""))
                       t))
         (pnt (car my/re-builder-positions))
         (beg (cadr my/re-builder-positions))
         (end (caddr my/re-builder-positions)))
    (with-selected-window reb-target-window
      (goto-char pnt) ; replace with (goto-char (match-beginning 0)) if you want
                                        ; to control where in the buffer the replacement starts
                                        ; with re-builder
      (setq my/re-builder-positions nil)
      (reb-quit)
      (query-replace-regexp re replacement delimited beg end))))

(with-eval-after-load 're-builder
  (define-advice re-builder (:around (orig-fun &rest args) query-replace)
    (setq my/re-builder-positions
          (cons (point)
                (when (region-active-p)
                  (list (region-beginning)
                        (region-end)))))  
    (apply orig-fun args)
  (message "Return:Query Replace,C-cC-c:quit")
    )
  
  (define-key reb-mode-map (kbd "RET") #'reb-replace-regexp)
  (define-key reb-lisp-mode-map (kbd "RET") #'reb-replace-regexp)
  (define-key reb-mode-map (kbd "C-c C-c") #'reb-quit))

(global-set-key (kbd "C-M-%") #'re-builder)