2

M-x sort-lines複数行の式を適切に処理できるバリアントを探しています。例えば:

this is the first line
this is the second lien
this is the (third 
             line
             spanning multiple lines because of parens)

何か案は?

4

1 に答える 1

3

これは、同様の方法で解決された同様の質問です

(defun end-of-chunk ()
  "forward line or to ends of mid-expression."
  (interactive)
  (goto-char (point-at-eol))
  (let ((limit (point-at-bol))
        temp
        expr-beg)
    (while (and (setq temp (nth 1 (syntax-ppss)))
                (<= limit temp))
      (goto-char temp)
      (setq expr-beg (point)))
    (when expr-beg
        (goto-char expr-beg)
      (forward-sexp))))

(defun sort-lines-as-exprs (reverse beg end)
  "sort lines, or whole expression if line ends mid-expression."
  (interactive "P\nr")
  (save-excursion
    (save-restriction
      (narrow-to-region beg end)
      (goto-char (point-min))
      (sort-subr reverse
                 'forward-line
                 'end-of-chunk))))
于 2013-01-18T14:27:17.837 に答える