代码之家  ›  专栏  ›  技术社区  ›  Naveen

Emacs击键表示混乱

  •  3
  • Naveen  · 技术社区  · 14 年前

    我通常在Emacs中使用

    "C-x (" --> (command kmacro-start-macro)
    "C-x )" --> (kmacro-end-macro)
    (name-last-kbd-macro)
    (insert-kbd-macro)
    
    But the code it generates looks different than the code I read and modify in various major / minor modes and other emacs utilities.
    我最近遇到 this 清除我的一些困惑的博客帖子。

    有没有一个Emacs工具可以简化击键表示? 理想情况下是从 ahk keystroke notation 任何健全的Emacs击键符号。

    编辑:其他一些阅读来澄清我的困惑: keybinding guide Jari Aalto。

    3 回复  |  直到 10 年前
        1
  •  5
  •   Community Egal    7 年前

    The sequence you specify does simplify the keystroke representation. What you're left with is essentially 这个 您键入的一组按键。

    已经有人问你是否可以转换 emacs macro into elisp .

    也许你在问它是否能让人更容易阅读? 如果是这样,那你就走运了。

    你可以使用 kbd 宏将打印的击键表示转换为等效的击键向量。

    例如,导致 query-replace 属于 3 具有 tj 看起来像: M-%3 ret tj ret!

    好吧,您可以手动设置为:

    (fset 'my-hand-crafted-kbd-macro (kbd "M-% 3 RET tj RET !"))
    

    如果您已经命名了宏,那么这段elisp代码应该为您生成上面的代码。 'my-hand-crafted-kbd-macro :

    (defun insert-pretty-kbd-macro (macro-name)
      (interactive (list (intern (completing-read
                                  "Insert kbd macro (name): "
                                  obarray
                                  (lambda (elt)
                                    (and (fboundp elt)
                                         (or (stringp (symbol-function elt))
                                             (vectorp (symbol-function elt))
                                             (get elt 'kmacro))))
                                  t))))
      (interactive)
      (insert "(fset '")
      (prin1 macro-name (current-buffer))
      (insert "\n   (kbd \"")
      (insert (key-description (symbol-function macro-name)))
      (insert "\"))\n"))
    

    完成键盘宏后自动执行此操作 C-X) ,您可以使用以下建议:

    (defadvice kmacro-end-macro (after kmacro-end-macro-name-it-and-insert activate)
      "user wants to insert elisp to reproduce the last kbd macro"
      (let ((name (read-string "Name for this kbd macro: ")))
        (insert "(fset '")
        (insert name)
        (insert "\n   (kbd \"")
        (insert (key-description last-kbd-macro))
        (insert "\"))\n")))
    
        2
  •  1
  •   Naveen    14 年前

    谢谢Trey。
    我将name last kbd宏和insert pretty kbd宏合并到name和insert last kbd宏中

    (defun name-and-insert-last-kbd-macro (macro-name)
      (interactive (list (intern (completing-read
                                  "Insert kbd macro (name): "
                                  obarray
                                  t))))
      (interactive)
      (insert "(fset '")
      (prin1 macro-name (current-buffer))
      (insert "\n   (kbd \"")
      (fset symbol last-kbd-macro)
      (insert (key-description (symbol-function symbol)))
      (insert "\"))\n"))
    现在,我可以开始用F8定义宏,
    结束并用F9测试/运行它
    ,并用F10命名和插入:
    (global-set-key [f8] 'kmacro-start-macro)
    (global-set-key [f9] 'kmacro-end-and-call-macro)
    (global-set-key [f10] 'name-and-insert-last-kbd-macro)
    (global-set-key [f12] 'menu-bar-open)  ; originally bound to F10
    
        3
  •  0
  •   Silex    10 年前

    I made a package that allows pretty much exactly this at https://github.com/Silex/elmacro

    它有一些怪癖,但效果很好…例如,以下宏:

    F3 C-e M-b M-u C-a C-n F4
    

    生成以下elisp:

    (defun upcase-last-word ()
      "Change me!"
      (interactive)
      (move-end-of-line 1)
      (backward-word 1)
      (upcase-word 1)
      (move-beginning-of-line 1)
      (next-line 1 1))