代码之家  ›  专栏  ›  技术社区  ›  Bryan Oakley

如何让Emacs打开一块代码?

  •  4
  • Bryan Oakley  · 技术社区  · 16 年前

    假设在Emacs缓冲区中有一行如下所示:

    foo -option1 value1 -option2 value2 -option3 value3 \
        -option4 value4 ...
    

    我希望它看起来像这样:

    foo -option1 value1 \
        -option2 value2 \
        -option3 value3 \
        -option4 value4 \
        ...
    

    我希望每个选项/值对在单独的行上。我还希望这些后续行根据模式适当缩进,而不是添加固定数量的空白。我希望代码在当前块上工作,在第一个非空白行或不包含选项/值对的行处停止,尽管我可以在选定区域上处理它。

    有人知道elisp函数吗?

    4 回复  |  直到 12 年前
        1
  •  2
  •   Trey Jackson    12 年前

    (defun tcl-multiline-options ()
      "spread option/value pairs across multiple lines with continuation characters"
      (interactive)
      (save-excursion
        (tcl-join-continuations)
        (beginning-of-line)
        (while (re-search-forward " -[^ ]+ +"  (line-end-position) t)
          (goto-char (match-beginning 0))
          (insert " \\\n")
          (goto-char (+(match-end 0) 3))
          (indent-according-to-mode)
          (forward-sexp))))
    
    (defun tcl-join-continuations ()
      "join multiple continuation lines into a single physical line"
      (interactive)
      (while (progn (end-of-line) (char-equal (char-before) ?\\))
        (forward-line 1))
      (while (save-excursion (end-of-line 0) (char-equal (char-before) ?\\))
        (end-of-line 0)
        (delete-char -1)
        (delete-char 1)
        (fixup-whitespace)))
    
        2
  •  1
  •   Jason Dagit    16 年前

        3
  •  0
  •   mike511    16 年前

        4
  •  0
  •   Allen    16 年前