sort-lines calls forward-line rather than forward-visible line, so if you have emacs outline entries that are collapsed/hidden to single lines each and you try to sort them, their bodies and subtrees are sorted separately because forward-visible-line is not used. This patch fixes this problem and also unifies the calling convention of forward-visible-line with that of forward-line (allowing it to take an optional argument) leading to a cleaner calling convention. Please apply it as soon as you can as Hyperbole uses sort-lines to sort its contact manager records and right now this doesn't work. Although, sort-subr could be called directly for this application, sort-lines should work properly with both visible and invisible text and the patch is quite simple. Thanks, Bob -------- In GNU Emacs 25.0.94.1 (x86_64-apple-darwin13.4.0, NS appkit-1265.21 Version 10.9.5 (Build 13F1603)) of 2016-05-17 built on builder10-9.local Windowing system distributor 'Apple', version 10.3.1404 Configured using: 'configure --with-ns '--enable-locallisppath=/Library/Application Support/Emacs/${version}/site-lisp:/Library/Application Support/Emacs/site-lisp'' Configured features: NOTIFY ACL LIBXML2 ZLIB TOOLKIT_SCROLL_BARS NS Important settings: value of $LANG: en_US.UTF-8 locale-coding-system: utf-8-unix ---------------- *** sort-orig.el.gz 2016-06-18 11:31:13.000000000 -0400 --- sort.el.gz 2016-06-18 11:31:13.000000000 -0400 *************** *** 210,216 **** (goto-char (point-min)) (let ;; To make `end-of-line' and etc. to ignore fields. ((inhibit-field-text-motion t)) ! (sort-subr reverse 'forward-line 'end-of-line))))) ;;;###autoload (defun sort-paragraphs (reverse beg end) --- 210,216 ---- (goto-char (point-min)) (let ;; To make `end-of-line' and etc. to ignore fields. ((inhibit-field-text-motion t)) ! (sort-subr reverse 'forward-visible-line 'end-of-visible-line))))) ;;;###autoload (defun sort-paragraphs (reverse beg end) *** simple-orig.el.gz 2016-06-18 11:29:58.000000000 -0400 --- simple.el.gz 2016-06-18 11:29:58.000000000 -0400 *************** *** 4909,4918 **** (kill-region (point) (progn (forward-visible-line arg) (point)))))) ! (defun forward-visible-line (arg) ! "Move forward by ARG lines, ignoring currently invisible newlines only. If ARG is negative, move backward -ARG lines. If ARG is zero, move to the beginning of the current line." (condition-case nil (if (> arg 0) (progn --- 4909,4919 ---- (kill-region (point) (progn (forward-visible-line arg) (point)))))) ! (defun forward-visible-line (&optional arg) ! "Move forward by optional ARG lines (default = 1), ignoring currently invisible newlines only. If ARG is negative, move backward -ARG lines. If ARG is zero, move to the beginning of the current line." + (if (null arg) (setq arg 1)) (condition-case nil (if (> arg 0) (progn