Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

functional line indentation logic

  • Loading branch information...
commit 63561e36f7a9b5b0887932feed04d459afe3e6b9 1 parent f8b5b06
Brian C brianc authored

Showing 1 changed file with 24 additions and 6 deletions. Show diff stats Hide diff stats

  1. +24 6 jade-mode.el
30 jade-mode.el
@@ -7,6 +7,10 @@
7 7 "Prints a debug message"
8 8 (apply 'message (append (list string) args)))
9 9
  10 +(defmacro jade-line-as-string ()
  11 + "Returns the current line as a string."
  12 + `(buffer-substring (point-at-bol) (point-at-eol)))
  13 +
10 14
11 15 (defun jade-indent-line ()
12 16 "Indents current line")
@@ -22,15 +26,29 @@
22 26 ;; should only indent if previous line is indented at most one less
23 27 (> (jade-previous-indentation) (- (current-indentation) 1)))
24 28
  29 +(defun jade-empty-line-p ()
  30 + "If line is empty or not."
  31 + (= (point-at-eol) (point-at-bol)))
  32 +
25 33 (defun jade-indent-line ()
26 34 "Indents the line."
27 35 (interactive)
28   - (if (jade-should-indent-p)
29   - (save-excursion
30   - (let ((ci (current-indentation)))
31   - (beginning-of-line)
32   - (delete-horizontal-space)
33   - (indent-to (+ jade-tab-width ci))))))
  36 +
  37 + ;; indent straight to end on empty line
  38 + (if (jade-empty-line-p)
  39 + (indent-to (jade-previous-indentation))
  40 + (if (jade-should-indent-p)
  41 + (progn
  42 + (save-excursion
  43 + (let ((ci (current-indentation)))
  44 + (beginning-of-line)
  45 + (delete-horizontal-space)
  46 + (indent-to (+ jade-tab-width ci))))
  47 + )))
  48 + ;; move point to end of line on empty lines to make tabbing
  49 + ;; more obvious
  50 + (if (string-match-p "^[ ]*$" (jade-line-as-string))
  51 + (move-end-of-line 1)))
34 52
35 53 (setq jade-font-lock-keywords
36 54 `((,"!!!\\( \\(default\\|5\\|transitional\\)\\)?" 0 font-lock-constant-face) ;; doctype

0 comments on commit 63561e3

Please sign in to comment.
Something went wrong with that request. Please try again.