[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] scratch/hyperbole-lexbind e1a95cc 04/20: Improve paragraph fillin
From: |
Stefan Monnier |
Subject: |
[elpa] scratch/hyperbole-lexbind e1a95cc 04/20: Improve paragraph filling to match newer Emacs versions |
Date: |
Wed, 14 Aug 2019 04:30:21 -0400 (EDT) |
branch: scratch/hyperbole-lexbind
commit e1a95cc9820cb9d5aaca947b3ddd836a055d3c60
Author: Bob Weiner <address@hidden>
Commit: Bob Weiner <address@hidden>
Improve paragraph filling to match newer Emacs versions
---
kotl/kfill.el | 97 +++++++++++++++++++++++++------------------------------
kotl/kotl-mode.el | 11 ++++---
2 files changed, 51 insertions(+), 57 deletions(-)
diff --git a/kotl/kfill.el b/kotl/kfill.el
index 0ceadb2..60ee307 100644
--- a/kotl/kfill.el
+++ b/kotl/kfill.el
@@ -29,12 +29,6 @@
;;; Public variables
;;; ************************************************************************
-(defvar kfill:function-table
- (if (featurep 'filladapt)
- filladapt-function-table
- (list (cons 'fill-paragraph (symbol-function 'fill-paragraph))))
- "Table containing the old function definitions that kfill overrides.")
-
(defvar kfill:prefix-table
'(
;; Lists with hanging indents, e.g.
@@ -117,44 +111,44 @@ number of lines that could not be moved, otherwise 0."
;; Need this or Emacs ignores fill-prefix when inside a
;; comment.
(comment-multi-line t)
+ (fill-paragraph-handle-comment t)
fill-prefix)
(kfill:adapt nil)
(do-auto-fill))
(do-auto-fill))))
-;;; Redefine this built-in function.
-
-(defun fill-paragraph (arg &optional skip-prefix-remove)
- "Fill paragraph at or after point. Prefix ARG means justify as well."
- (interactive "*P")
- (if (not (eq major-mode 'kotl-mode))
- (kfill:funcall 'fill-paragraph arg)
- ;; This may be called from `fill-region-as-paragraph' in "filladapt.el"
- ;; which narrows the region to the current paragraph. A side-effect is
- ;; that the cell identifier and indent information needed by this function
- ;; when in kotl-mode is no longer visible. So we temporarily rewiden the
- ;; buffer here. Don't rewiden past the paragraph of interest or any
- ;; following blank line may be removed by the filling routines.
- (save-restriction
- (if (eq major-mode 'kotl-mode)
- (narrow-to-region 1 (point-max)))
- ;; Emacs expects a specific symbol here.
- (if (and arg (not (symbolp arg))) (setq arg 'full))
- (or skip-prefix-remove (kfill:remove-paragraph-prefix))
- (catch 'done
- (if (null fill-prefix)
- (let ((paragraph-ignore-fill-prefix nil)
- ;; Need this or Emacs ignores fill-prefix when
- ;; inside a comment.
- (comment-multi-line t)
- (paragraph-start paragraph-start)
- (paragraph-separate paragraph-separate)
- fill-prefix)
- (if (kfill:adapt t)
- (throw 'done (kfill:funcall 'fill-paragraph arg)))))
- ;; Kfill:adapt failed or fill-prefix is set, so do a basic
- ;; paragraph fill as adapted from par-align.el.
- (kfill:fallback-fill-paragraph arg skip-prefix-remove)))))
+(defun kfill:fill-paragraph (&optional arg skip-prefix-remove)
+ "Fill paragraph at or after point when in kotl-mode. Prefix ARG means
justify as well."
+ (interactive (progn
+ (barf-if-buffer-read-only)
+ (list (if current-prefix-arg 'full) nil)))
+ ;; This may be called from `fill-region-as-paragraph' in "filladapt.el"
+ ;; which narrows the region to the current paragraph. A side-effect is
+ ;; that the cell identifier and indent information needed by this function
+ ;; when in kotl-mode is no longer visible. So we temporarily rewiden the
+ ;; buffer here. Don't rewiden past the paragraph of interest or any
+ ;; following blank line may be removed by the filling routines.
+ (save-restriction
+ (if (eq major-mode 'kotl-mode)
+ (narrow-to-region 1 (point-max)))
+ ;; Emacs expects a specific symbol here.
+ (if (and arg (not (symbolp arg))) (setq arg 'full))
+ (or skip-prefix-remove (kfill:remove-paragraph-prefix))
+ (catch 'done
+ (if (null fill-prefix)
+ (let ((paragraph-ignore-fill-prefix nil)
+ ;; Need this or Emacs ignores fill-prefix when
+ ;; inside a comment.
+ (comment-multi-line t)
+ (fill-paragraph-handle-comment t)
+ (paragraph-start paragraph-start)
+ (paragraph-separate paragraph-separate)
+ fill-prefix)
+ (if (kfill:adapt t)
+ (throw 'done (fill-paragraph arg)))))
+ ;; Kfill:adapt failed or fill-prefix is set, so do a basic
+ ;; paragraph fill as adapted from par-align.el.
+ (kfill:fallback-fill-paragraph arg skip-prefix-remove))))
;;;
;;; Redefine this built-in function so that it sets `prior-fill-prefix' also.
@@ -165,16 +159,17 @@ Also sets `prior-fill-prefix' to the previous value of
`fill-prefix'.
Filling removes any prior fill prefix, adjusts line lengths and then adds the
fill prefix at the beginning of each line."
(interactive)
- (setq prior-fill-prefix fill-prefix
- fill-prefix (if turn-off
- nil
- (buffer-substring
- (save-excursion (beginning-of-line) (point))
- (point))))
- (if (equal prior-fill-prefix "")
- (setq prior-fill-prefix nil))
- (if (equal fill-prefix "")
- (setq fill-prefix nil))
+ (setq prior-fill-prefix fill-prefix)
+ (let ((left-margin-pos (save-excursion (move-to-left-margin) (point))))
+ (if (> (point) left-margin-pos)
+ (setq fill-prefix (if turn-off
+ nil
+ (buffer-substring left-margin-pos (point))))
+ (setq fill-prefix nil)))
+ (when (equal prior-fill-prefix "")
+ (setq prior-fill-prefix nil))
+ (when (equal fill-prefix "")
+ (setq fill-prefix nil))
(cond (fill-prefix
(message "fill-prefix: \"%s\"; prior-fill-prefix: \"%s\""
fill-prefix (or prior-fill-prefix "")))
@@ -237,10 +232,6 @@ fill prefix at the beginning of each line."
(funcall function justify-flag)))
(fill-region-as-paragraph from (point) justify-flag)))))
-(defun kfill:funcall (function &rest args)
- "Call the original FUNCTION with rest of ARGS that kfill overloaded."
- (apply (cdr (assq function kfill:function-table)) args))
-
(defun kfill:hanging-list (paragraph)
(let (prefix match beg end)
(setq prefix (make-string (- (match-end 0) (match-beginning 0)) ?\ ))
diff --git a/kotl/kotl-mode.el b/kotl/kotl-mode.el
index 7deefb5..ce3e570 100644
--- a/kotl/kotl-mode.el
+++ b/kotl/kotl-mode.el
@@ -79,6 +79,7 @@ It provides the following keys:
;; Some package such as filladapt has overwritten the primitives
;; defined in kfill.el, so reload it.
(load "kfill"))
+ (setq fill-paragraph-function #'kfill:fill-paragraph)
;; Ensure that outline structure data is saved when save-buffer is called
;; from save-some-buffers, {C-x s}.
(add-hook 'local-write-file-hooks #'kotl-mode:update-buffer)
@@ -153,7 +154,7 @@ It provides the following keys:
(kvspec:activate))))
;; We have been converting a buffer from a foreign format to a koutline.
;; Now that it is converted, ensure that `kotl-previous-mode' is set to
- ;; koutline now.
+ ;; koutline.
(setq kotl-previous-mode 'kotl-mode)
(run-hooks 'kotl-mode-hook)
(add-hook 'change-major-mode-hook #'kotl-mode:show-all nil t))
@@ -675,15 +676,17 @@ too long."
With arg N, insert N newlines."
(interactive "*p")
(let* ((bolp (and (kotl-mode:bolp) (not (kotl-mode:bocp))))
- (indent (kcell-view:indent)))
+ (indent (kcell-view:indent))
+ (add-prefix (and (stringp fill-prefix)
+ (not (string-empty-p fill-prefix)))))
(while (> arg 0)
(save-excursion
(insert ?\n)
- (if (and (not bolp) fill-prefix)
+ (if (and (not bolp) add-prefix)
(insert fill-prefix)
(insert-char ?\ indent)))
(setq arg (1- arg)))
- (if (and bolp fill-prefix)
+ (if (and bolp add-prefix)
(progn (delete-horizontal-space)
(insert fill-prefix)))))
- [elpa] scratch/hyperbole-lexbind updated (98a5ecb -> 6e555e7), Stefan Monnier, 2019/08/14
- [elpa] scratch/hyperbole-lexbind a65ee22 03/20: Small coding improvements, Stefan Monnier, 2019/08/14
- [elpa] scratch/hyperbole-lexbind 91e8a73 02/20: Add texinfo pathname section references; improve internal image links, Stefan Monnier, 2019/08/14
- [elpa] scratch/hyperbole-lexbind e1a95cc 04/20: Improve paragraph filling to match newer Emacs versions,
Stefan Monnier <=
- [elpa] scratch/hyperbole-lexbind 60d51ad 12/20: Remove last references to XEmscs and xterm used under Emacs 18, Stefan Monnier, 2019/08/14
- [elpa] scratch/hyperbole-lexbind af55195 05/20: Make Action Key handle bi-directional jumping for Org mode radio target and internal links, Stefan Monnier, 2019/08/14
- [elpa] scratch/hyperbole-lexbind 36e4724 01/20: 7.0.3a bug fixes; add link-to-ibut, link-to-gbut, Stefan Monnier, 2019/08/14
- [elpa] scratch/hyperbole-lexbind e647502 18/20: BSD zgrep support for Hyperbole grep command, Stefan Monnier, 2019/08/14
- [elpa] scratch/hyperbole-lexbind 0829631 13/20: Fix small logic errors in new e/g/ilink functions, Stefan Monnier, 2019/08/14
- [elpa] scratch/hyperbole-lexbind b128464 06/20: Update Changes and add 7.0.3 release message to HY-ANNOUNCE, Stefan Monnier, 2019/08/14
- [elpa] scratch/hyperbole-lexbind 332ef33 19/20: V7.0.3b test release: Basic DEMO updates, Stefan Monnier, 2019/08/14
- [elpa] scratch/hyperbole-lexbind c547ad4 10/20: Merge branch '7.0.3a' into prepare-pr-for-merging, Stefan Monnier, 2019/08/14
- [elpa] scratch/hyperbole-lexbind 131295e 07/20: Remove conditionals on xemacs, Stefan Monnier, 2019/08/14
- [elpa] scratch/hyperbole-lexbind ff0f602 11/20: Merge pull request #11 from matsl/prepare-pr-for-merging, Stefan Monnier, 2019/08/14