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 回答