[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/forth-mode 93756ec224 005/153: Some basic and flawed suppo
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/forth-mode 93756ec224 005/153: Some basic and flawed support for block files. |
Date: |
Sat, 29 Jan 2022 08:02:11 -0500 (EST) |
branch: elpa/forth-mode
commit 93756ec224a0fc341d6436f5c63bf904d4da68a2
Author: Lars Brinkhoff <lars@nocrew.org>
Commit: Lars Brinkhoff <lars@nocrew.org>
Some basic and flawed support for block files.
---
TMP | 1 +
block.fth | 1 +
forth-block-mode.el | 89 ++++++++++++++++++++++++++++++++++++++++++++++++++++-
forth-mode.el | 4 +++
4 files changed, 94 insertions(+), 1 deletion(-)
diff --git a/TMP b/TMP
new file mode 100644
index 0000000000..009ec3a0bb
--- /dev/null
+++ b/TMP
@@ -0,0 +1 @@
+( Screen #1 -------------------------------------------------- \
\ Line 2
\
\
\ \
\
[...]
\ No newline at end of file
diff --git a/block.fth b/block.fth
new file mode 100644
index 0000000000..5d68241302
--- /dev/null
+++ b/block.fth
@@ -0,0 +1 @@
+( Screen #1 -------------------------------------------------- )\
\ Line 2
\
\
\ \
\
[...]
\ No newline at end of file
diff --git a/forth-block-mode.el b/forth-block-mode.el
index 5edbbf0524..0e4a857be1 100644
--- a/forth-block-mode.el
+++ b/forth-block-mode.el
@@ -1,3 +1,90 @@
+(defun forth-block-p ()
+ "Guess whether the current buffer is a Forth block file."
+ (message (format "%s %s" (point-max) (logand (point-max) 1023)))
+ (and (eq (logand (point-max) 1023) 1)
+ (save-excursion
+ (beginning-of-buffer)
+ (not (search-forward "\n" 1024 t)))))
+
+(defun forth-unblockify ()
+ (let ((after-change-functions nil))
+ (save-excursion
+ (beginning-of-buffer)
+ (while (ignore-errors (forward-char 64) t)
+ (insert ?\n))
+ (let ((delete-trailing-lines t))
+ (delete-trailing-whitespace))
+ (set-buffer-modified-p nil))))
+
+(defun forth-pad-line ()
+ (end-of-line)
+ (while (plusp (logand (1- (point)) 63))
+ (insert " "))
+ (ignore-errors (delete-char 1)
+ (if (looking-at "\n")
+ (insert " "))
+ t))
+
+(defun forth-blockify ()
+ (let ((after-change-functions nil))
+ (save-excursion
+ (beginning-of-buffer)
+ (while (forth-pad-line))
+ (while (plusp (logand (point) 1023))
+ (insert " "))
+ (insert " "))))
+
+(defun forth-block-annotations ())
+
+;;; format-alist
+'(forth/blocks "Forth blocks" nil forth-unblockify forth-block-annotations
+ nil forth-block-mode nil)
+
+(defvar forth-change-newlines)
+
+(defun forth-count-newlines (start end)
+ (let ((n 0))
+ (save-excursion
+ (goto-char start)
+ (while (< (point) end)
+ (if (looking-at "\n")
+ (incf n))
+ (forward-char 1)))
+ (message "N = %d" n)
+ n))
+
+(defun forth-before-change (start end)
+ (setq forth-change-newlines (forth-count-newlines start end)))
+
+(defun forth-after-change (start end z)
+ (message "Change: %s %s %s" start end z)
+ (setq forth-change-newlines (- (forth-count-newlines start end)
+ forth-change-newlines))
+ (message "New lines: %d" forth-change-newlines)
+ (cond ((plusp forth-change-newlines)
+ (let ((n (logand (+ (line-number-at-pos) 15) -16)))
+ (save-excursion
+ (goto-line (1+ n))
+ (delete-region (line-beginning-position) (line-end-position))
+ (delete-char 1))))
+ ((minusp forth-change-newlines)
+ (let ((n (logand (+ (line-number-at-pos) 15) -16)))
+ (save-excursion
+ (goto-line n)
+ (insert "\n")))))
+ (save-excursion
+ (end-of-line)
+ (while (> (- (point) (line-beginning-position)) 64)
+ (delete-backward-char 1))))
+
(define-minor-mode forth-block-mode
"Minor mode for Forth code in blocks."
- :lighter " block")
+ :lighter " block"
+ (setq require-final-newline nil)
+ (forth-unblockify)
+ (add-hook (make-local-variable 'before-save-hook) #'forth-blockify)
+ (add-hook (make-local-variable 'after-save-hook) #'forth-unblockify)
+ (add-to-list (make-local-variable 'before-change-functions)
+ #'forth-before-change)
+ (add-to-list (make-local-variable 'after-change-functions)
+ #'forth-after-change))
diff --git a/forth-mode.el b/forth-mode.el
index 1360b629cd..8247d8a868 100644
--- a/forth-mode.el
+++ b/forth-mode.el
@@ -1,6 +1,8 @@
;;;; -*- emacs-lisp -*-
;;; Copyright 2014 Lars Brinkhoff
+(load-file "forth-block-mode.el")
+
(defvar forth-mode-map
(let ((map (make-sparse-keymap)))
;; (define-key (kbd "C-x C-e") #'forth-eval-last-sexp)
@@ -60,6 +62,8 @@
(define-derived-mode forth-mode prog-mode "Forth"
"Major mode for editing Forth files."
:syntax-table forth-mode-syntax-table
+ (if (forth-block-p)
+ (forth-block-mode))
(setq font-lock-defaults '(forth-font-lock-keywords))
(setq ;; font-lock-defaults
indent-line-function #'forth-indent
- [nongnu] elpa/forth-mode 9300eb75c4 025/153: Remove stubs., (continued)
- [nongnu] elpa/forth-mode 9300eb75c4 025/153: Remove stubs., ELPA Syncer, 2022/01/29
- [nongnu] elpa/forth-mode 778470cbcb 014/153: Load a file into an interactive Forth session., ELPA Syncer, 2022/01/29
- [nongnu] elpa/forth-mode 9855800cb7 053/153: Start a user manual., ELPA Syncer, 2022/01/29
- [nongnu] elpa/forth-mode 3deee67777 097/153: Emacs 23: Don't test font-lock., ELPA Syncer, 2022/01/29
- [nongnu] elpa/forth-mode b455a556fe 056/153: Add C-M-x, forth-eval-defun., ELPA Syncer, 2022/01/29
- [nongnu] elpa/forth-mode 973481a1c5 007/153: Add some autoloads., ELPA Syncer, 2022/01/29
- [nongnu] elpa/forth-mode 244c416c4d 013/153: Variable for secifying Forth executable., ELPA Syncer, 2022/01/29
- [nongnu] elpa/forth-mode cdab2e4ec1 038/153: Also recognise .4th., ELPA Syncer, 2022/01/29
- [nongnu] elpa/forth-mode 695bb04ebc 002/153: A humble beginning., ELPA Syncer, 2022/01/29
- [nongnu] elpa/forth-mode 24d3d052fe 003/153: More work. Font lock and navigation somewhat usable., ELPA Syncer, 2022/01/29
- [nongnu] elpa/forth-mode 93756ec224 005/153: Some basic and flawed support for block files.,
ELPA Syncer <=
- [nongnu] elpa/forth-mode bca8f01218 004/153: Make it work in older Emacsen without prog-mode., ELPA Syncer, 2022/01/29
- [nongnu] elpa/forth-mode effb52b8e0 009/153: Load files from load-path., ELPA Syncer, 2022/01/29
- [nongnu] elpa/forth-mode 3047dfa37a 008/153: Run a subprocess Forth for interaction., ELPA Syncer, 2022/01/29
- [nongnu] elpa/forth-mode 6ab334684b 010/153: Send a string to an interactive Forth session., ELPA Syncer, 2022/01/29
- [nongnu] elpa/forth-mode b6b1f049b0 017/153: Restart an interactive Forth session., ELPA Syncer, 2022/01/29
- [nongnu] elpa/forth-mode 7c75c452e9 022/153: Correct autoload cookie format, ELPA Syncer, 2022/01/29
- [nongnu] elpa/forth-mode e4ed4a8acf 050/153: Test with both Emacs 23 and 24., ELPA Syncer, 2022/01/29
- [nongnu] elpa/forth-mode cc267b4b85 043/153: Symbol completion. Candidates come from a running Forth., ELPA Syncer, 2022/01/29
- [nongnu] elpa/forth-mode 50adf0d552 024/153: Remove byte-compile warnings., ELPA Syncer, 2022/01/29
- [nongnu] elpa/forth-mode 85ce58e93e 020/153: Correct package header format, ELPA Syncer, 2022/01/29