[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/jade-mode 5752db7c36 012/128: added significant whitespace
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/jade-mode 5752db7c36 012/128: added significant whitespace mode as sub-mode for jade-mode and (soon to be) stylus-mode |
Date: |
Sat, 29 Jan 2022 08:24:42 -0500 (EST) |
branch: elpa/jade-mode
commit 5752db7c363bc20bf432af68b5b809a75f47bd85
Author: Brian Carlson <brian.m.carlson@gmail.com>
Commit: Brian Carlson <brian.m.carlson@gmail.com>
added significant whitespace mode as sub-mode for jade-mode and (soon to
be) stylus-mode
---
sws-mode.el | 132 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 132 insertions(+)
diff --git a/sws-mode.el b/sws-mode.el
new file mode 100644
index 0000000000..18524022fe
--- /dev/null
+++ b/sws-mode.el
@@ -0,0 +1,132 @@
+(require 'font-lock)
+
+(defvar sws-tab-width 2)
+
+(defmacro sws-line-as-string ()
+ "Returns the current line as a string."
+ `(buffer-substring (point-at-bol) (point-at-eol)))
+
+(defun sws-previous-indentation ()
+ "Gets indentation of previous line"
+ (save-excursion
+ (previous-line)
+ (current-indentation)))
+
+(defun sws-max-indent ()
+ "Calculates max indentation"
+ (+ (sws-previous-indentation) sws-tab-width))
+
+(defun sws-empty-line-p ()
+ "If line is completely empty"
+ (= (point-at-bol) (point-at-eol)))
+
+(defun sws-point-to-bot ()
+ "Moves point to beginning of text"
+ (let ((ci (current-indentation)))
+ (beginning-of-line)
+ (delete-horizontal-space)
+ (indent-to ci)))
+
+(defun sws-do-indent-line ()
+ "Performs line indentation"
+ ;;if we are not tabbed out past max indent
+ (if (< (current-indentation) (sws-max-indent))
+ (indent-to (+ (current-indentation) sws-tab-width))
+ ;; if at max indent move text to beginning of line
+ (progn
+ (beginning-of-line)
+ (delete-horizontal-space))))
+
+(defun sws-indent-line ()
+ "Indents current line"
+ (interactive)
+ (if (region-active-p)
+ (sws-indent-region)
+ (if (sws-at-bot-p)
+ (sws-do-indent-line)
+ ;; instead of adjusting indent, move point to text
+ (sws-point-to-bot))))
+
+(defun sws-at-bol-p ()
+ "If point is at beginning of line"
+ (= (point) (point-at-bol)))
+
+(defun sws-at-bot-p ()
+ "If point is at beginning of text"
+ (= (point) (+ (current-indentation) (point-at-bol))))
+
+(defun sws-print-line-number ()
+ "Prints line number"
+ (sws-print-num (point)))
+
+(defun sws-print-num (arg)
+ "Prints line number"
+ (message (number-to-string arg)))
+
+(defun sws-indent-to (num)
+ "Force indentation to level including those below current level"
+ (save-excursion
+ (beginning-of-line)
+ (delete-horizontal-space)
+ (indent-to num)))
+
+(defun sws-move-region (begin end prog)
+ "Moves left is dir is null, otherwise right. prog is '+ or '-"
+ (save-excursion
+ (let (first-indent indent-diff)
+ (goto-char begin)
+ (setq first-indent (current-indentation))
+ (sws-indent-to
+ (funcall prog first-indent sws-tab-width))
+ (setq indent-diff (- (current-indentation) first-indent))
+ ;; move other lines based on movement of first line
+ (while (< (point) end)
+ (forward-line 1)
+ (if (< (point) end)
+ (sws-indent-to (+ (current-indentation) indent-diff)))))))
+
+(defun sws-indent-region (begin end)
+ "Indents the selected region"
+ (interactive)
+ (sws-move-region begin end '+))
+
+
+(defun sws-dendent-line ()
+ "De-indents current line"
+ (interactive)
+ (if (region-active-p)
+ (sws-move-region (region-beginning) (region-end) '-)
+ (if (sws-at-bol-p)
+ (progn
+ (delete-horizontal-space)
+ (indent-to (sws-max-indent)))
+ (let ((ci (current-indentation)))
+ (beginning-of-line)
+ (delete-horizontal-space)
+ (indent-to (- ci sws-tab-width))))))
+
+(defvar sws-mode-map (make-sparse-keymap))
+(define-key sws-mode-map [S-tab] 'sws-dendent-line)
+
+(define-derived-mode sws-mode fundamental-mode
+ "sws"
+ "Major mode for editing significant whitespace files"
+ (kill-all-local-variables)
+
+ ;; default tab width
+ (setq sws-tab-width 2)
+ (make-local-variable 'indent-line-function)
+ (setq indent-line-function 'sws-indent-line)
+ (make-local-variable 'indent-region-function)
+
+ (setq indent-region-function 'sws-indent-region)
+
+ ;; TODO needed?
+ (setq indent-tabs-mode nil)
+
+ ;; keymap
+ (use-local-map sws-mode-map)
+
+ (setq major-mode 'sws-mode))
+
+(provide 'sws-mode)
- [nongnu] elpa/jade-mode c4014d8a9c 098/128: Merge pull request #50 from tjefferson08/46_unit_tests, (continued)
- [nongnu] elpa/jade-mode c4014d8a9c 098/128: Merge pull request #50 from tjefferson08/46_unit_tests, ELPA Syncer, 2022/01/29
- [nongnu] elpa/jade-mode e9288f66dc 106/128: use named regexes in font-lock-keywords list, ELPA Syncer, 2022/01/29
- [nongnu] elpa/jade-mode f9522fc00a 105/128: reorder highlight tests to match regex order in jade-mode.el and display, ELPA Syncer, 2022/01/29
- [nongnu] elpa/jade-mode 97c460453b 116/128: Merge pull request #62 from robbyoconnor/remove-flymake-from-README, ELPA Syncer, 2022/01/29
- [nongnu] elpa/jade-mode 93c0dec9d4 121/128: fix `.pug` extension to be auto-loaded, ELPA Syncer, 2022/01/29
- [nongnu] elpa/jade-mode 4dbde92542 122/128: Merge pull request #68 from chillum/master, ELPA Syncer, 2022/01/29
- [nongnu] elpa/jade-mode 1ad7c51f3c 128/128: Merge pull request #72 from he-la/master, ELPA Syncer, 2022/01/29
- [nongnu] elpa/jade-mode 91c2d4be67 019/128: update to include keybinding information, ELPA Syncer, 2022/01/29
- [nongnu] elpa/jade-mode ac71830de7 096/128: [#46] add Makefile and .travis.yml, ELPA Syncer, 2022/01/29
- [nongnu] elpa/jade-mode a61ad07db6 094/128: Merge pull request #42 from tjefferson08/doctype_fontification, ELPA Syncer, 2022/01/29
- [nongnu] elpa/jade-mode 5752db7c36 012/128: added significant whitespace mode as sub-mode for jade-mode and (soon to be) stylus-mode,
ELPA Syncer <=
- [nongnu] elpa/jade-mode 2f0f55cae4 018/128: updated readme, ELPA Syncer, 2022/01/29
- [nongnu] elpa/jade-mode 823c573c29 042/128: Merge pull request #5 from ntotani/master, ELPA Syncer, 2022/01/29
- [nongnu] elpa/jade-mode 97e1db63be 088/128: fix error while fontifying pipe regions, ELPA Syncer, 2022/01/29
- [nongnu] elpa/jade-mode 936b4a974b 115/128: Remove flymake mentions from the README, ELPA Syncer, 2022/01/29
- [nongnu] elpa/jade-mode fd367b9489 076/128: Remove unnecessary code from README, ELPA Syncer, 2022/01/29
- [nongnu] elpa/jade-mode dfeadc97a5 069/128: Merge pull request #31 from tjefferson08/26_comment_highlight, ELPA Syncer, 2022/01/29
- [nongnu] elpa/jade-mode 6b9d9507e2 010/128: can detect simple region sexps, ELPA Syncer, 2022/01/29
- [nongnu] elpa/jade-mode d28d1810fa 007/128: basic decrement tab working, ELPA Syncer, 2022/01/29
- [nongnu] elpa/jade-mode cb82d16486 017/128: jade-mode depends on sws-mode, ELPA Syncer, 2022/01/29
- [nongnu] elpa/jade-mode e4c668bde5 023/128: Have documentation such that jade-mode is used for .jade files., ELPA Syncer, 2022/01/29