summaryrefslogtreecommitdiff
path: root/lisp
diff options
context:
space:
mode:
Diffstat (limited to 'lisp')
-rw-r--r--lisp/bindings.el2
-rw-r--r--lisp/electric.el1
-rw-r--r--lisp/progmodes/prog-mode.el2
-rw-r--r--lisp/simple.el52
-rw-r--r--lisp/textmodes/text-mode.el6
5 files changed, 62 insertions, 1 deletions
diff --git a/lisp/bindings.el b/lisp/bindings.el
index 057c870958d..eec51a4e413 100644
--- a/lisp/bindings.el
+++ b/lisp/bindings.el
@@ -1522,7 +1522,7 @@ if `inhibit-field-text-motion' is non-nil."
(define-key special-event-map [sigusr2] 'ignore)
;; Text conversion
-(define-key global-map [text-conversion] 'ignore)
+(define-key global-map [text-conversion] 'analyze-text-conversion)
;; Don't look for autoload cookies in this file.
;; Local Variables:
diff --git a/lisp/electric.el b/lisp/electric.el
index bac3f5a2b3c..3865d1d5234 100644
--- a/lisp/electric.el
+++ b/lisp/electric.el
@@ -294,6 +294,7 @@ or comment."
;;;###autoload
(define-key global-map "\C-j" 'electric-newline-and-maybe-indent)
+
;;;###autoload
(defun electric-newline-and-maybe-indent ()
"Insert a newline.
diff --git a/lisp/progmodes/prog-mode.el b/lisp/progmodes/prog-mode.el
index 04071703184..7a53399ad14 100644
--- a/lisp/progmodes/prog-mode.el
+++ b/lisp/progmodes/prog-mode.el
@@ -336,6 +336,8 @@ support it."
(setq-local require-final-newline mode-require-final-newline)
(setq-local parse-sexp-ignore-comments t)
(add-hook 'context-menu-functions 'prog-context-menu 10 t)
+ ;; Enable text conversion in this buffer.
+ (setq-local text-conversion-style t)
;; Any programming language is always written left to right.
(setq bidi-paragraph-direction 'left-to-right))
diff --git a/lisp/simple.el b/lisp/simple.el
index bed6dfb8292..6a12585a55d 100644
--- a/lisp/simple.el
+++ b/lisp/simple.el
@@ -10864,6 +10864,58 @@ If the buffer doesn't exist, create it first."
"Change value in PLIST of PROP to VAL, comparing with `equal'."
(declare (obsolete plist-put "29.1"))
(plist-put plist prop val #'equal))
+
+
+
+;; Text conversion support. See textconv.c for more details about
+;; what this is.
+
+
+;; Actually in textconv.c.
+(defvar text-conversion-edits)
+
+(defun analyze-text-conversion ()
+ "Analyze the results of the previous text conversion event.
+
+For each insertion:
+
+ - Look for the insertion of a string starting or ending with a
+ character inside `auto-fill-chars', and fill the text around
+ it if `auto-fill-mode' is enabled.
+
+ - Look for the insertion of a new line, and cause automatic
+ line breaking of the previous line when `auto-fill-mode' is
+ enabled.
+
+ - Look for the insertion of a new line, and indent this new
+ line if `electric-indent-mode' is enabled."
+ (interactive)
+ (dolist (edit text-conversion-edits)
+ ;; Filter out ephemeral edits and deletions.
+ (when (and (not (eq (nth 1 edit) (nth 2 edit)))
+ (stringp (nth 3 edit)))
+ (with-current-buffer (car edit)
+ (let* ((inserted (nth 3 edit))
+ ;; Get the first and last characters.
+ (start (aref inserted 0))
+ (end (aref inserted (1- (length inserted))))
+ ;; Figure out whether or not to auto-fill.
+ (auto-fill-p (or (aref auto-fill-chars start)
+ (aref auto-fill-chars end)))
+ ;; Figure out whether or not a newline was inserted.
+ (newline-p (string-search "\n" inserted)))
+ (save-excursion
+ (if (and auto-fill-function newline-p)
+ (progn (goto-char (nth 2 edit))
+ (previous-logical-line)
+ (funcall auto-fill-function))
+ (when (and auto-fill-function auto-fill-p)
+ (progn (goto-char (nth 2 edit))
+ (funcall auto-fill-function)))))
+ (when (and electric-indent-mode newline-p)
+ (goto-char (nth 2 edit))
+ (indent-according-to-mode)))))))
+
(provide 'simple)
diff --git a/lisp/textmodes/text-mode.el b/lisp/textmodes/text-mode.el
index 48cefc74d06..ccba1b063ab 100644
--- a/lisp/textmodes/text-mode.el
+++ b/lisp/textmodes/text-mode.el
@@ -41,6 +41,9 @@
"Non-nil if this buffer's major mode is a variant of Text mode.")
(make-obsolete-variable 'text-mode-variant 'derived-mode-p "27.1")
+;; Actually defined in textconv.c.
+(defvar text-conversion-style)
+
(defvar text-mode-syntax-table
(let ((st (make-syntax-table)))
(modify-syntax-entry ?\" ". " st)
@@ -125,6 +128,9 @@ You can thus get the full benefit of adaptive filling
Turning on Text mode runs the normal hook `text-mode-hook'."
(setq-local text-mode-variant t)
(setq-local require-final-newline mode-require-final-newline)
+
+ ;; Enable text conversion in this buffer.
+ (setq-local text-conversion-style t)
(add-hook 'context-menu-functions 'text-mode-context-menu 10 t))
(define-derived-mode paragraph-indent-text-mode text-mode "Parindent"