Skip to content

Instantly share code, notes, and snippets.

@no-defun-allowed
Last active January 19, 2023 01:20
Show Gist options
  • Save no-defun-allowed/34b097954cc5af6f80abbd2f7fa94f77 to your computer and use it in GitHub Desktop.
Save no-defun-allowed/34b097954cc5af6f80abbd2f7fa94f77 to your computer and use it in GitHub Desktop.

Revisions

  1. no-defun-allowed revised this gist Jan 19, 2023. No changes.
  2. no-defun-allowed revised this gist Apr 14, 2022. No changes.
  3. no-defun-allowed revised this gist Mar 25, 2022. 1 changed file with 1 addition and 7 deletions.
    8 changes: 1 addition & 7 deletions variable-pitch-indent.el
    Original file line number Diff line number Diff line change
    @@ -47,11 +47,5 @@
    lines)))

    (defun variable-pitch-hook-handler (s e l)
    (when (member this-command '(self-insert-command
    newline
    slime-autodoc-space
    indent-for-tab-command
    backward-delete-char-untabify
    yank))
    (variable-pitch-indent)))
    (variable-pitch-indent))
    (push 'variable-pitch-hook-handler after-change-functions)
  4. no-defun-allowed revised this gist Mar 23, 2022. 1 changed file with 8 additions and 5 deletions.
    13 changes: 8 additions & 5 deletions variable-pitch-indent.el
    Original file line number Diff line number Diff line change
    @@ -14,7 +14,8 @@
    (save-excursion
    (let ((spine "")
    (face `(:foreground ,(face-attribute 'default :background nil)))
    (needs-full? (not *vpi-did-full-indent?*)))
    (needs-full? (not *vpi-did-full-indent?*))
    (lines 0))
    ;; Start early if we know the rest of the buffer is okay. Note
    ;; that we won't propagate anything beyond lines with no
    ;; indentation.
    @@ -24,8 +25,8 @@
    (while (not (eobp))
    (back-to-indentation)
    ;; Get out early if we know the rest of the buffer is okay.
    (when (and (not needs-full?) (zerop (current-column)))
    (return-from variable-pitch-indent))
    (when (and (not needs-full?) (zerop (current-column)) (plusp lines))
    (return-from variable-pitch-indent lines))
    (unless (eolp)
    (let* ((indentation-amount (current-column))
    (spine-cut (min (length spine) indentation-amount))
    @@ -40,8 +41,10 @@
    (put-text-property (point-at-bol) (point) 'display
    (propertize (concat spine-prefix spine-padding)
    'face face))))
    (forward-line 1))
    (when needs-full? (setf *vpi-did-full-indent?* t)))))
    (forward-line 1)
    (incf lines))
    (when needs-full? (setf *vpi-did-full-indent?* t))
    lines)))

    (defun variable-pitch-hook-handler (s e l)
    (when (member this-command '(self-insert-command
  5. no-defun-allowed created this gist Mar 22, 2022.
    54 changes: 54 additions & 0 deletions variable-pitch-indent.el
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,54 @@
    ;; A grown up version of https://lists.gnu.org/archive/html/emacs-devel/2018-03/msg00127.html

    (defvar-local *vpi-did-full-indent?* nil)

    (defun vpi-find-start ()
    (loop
    (back-to-indentation)
    (when (or (= (point-min) (point)) (zerop (current-column)))
    (return))
    (forward-line -1)))

    (cl-defun variable-pitch-indent ()
    (interactive)
    (save-excursion
    (let ((spine "")
    (face `(:foreground ,(face-attribute 'default :background nil)))
    (needs-full? (not *vpi-did-full-indent?*)))
    ;; Start early if we know the rest of the buffer is okay. Note
    ;; that we won't propagate anything beyond lines with no
    ;; indentation.
    (if needs-full?
    (goto-char (point-min))
    (vpi-find-start))
    (while (not (eobp))
    (back-to-indentation)
    ;; Get out early if we know the rest of the buffer is okay.
    (when (and (not needs-full?) (zerop (current-column)))
    (return-from variable-pitch-indent))
    (unless (eolp)
    (let* ((indentation-amount (current-column))
    (spine-cut (min (length spine) indentation-amount))
    (spine-prefix (substring spine 0 spine-cut))
    (spine-padding (make-string (- indentation-amount spine-cut) ?\s))
    (spine-end (buffer-substring (point) (point-at-eol))))
    (setq spine
    (with-temp-buffer
    (insert spine-prefix spine-padding spine-end)
    (untabify (point-min) (point-max))
    (buffer-string)))
    (put-text-property (point-at-bol) (point) 'display
    (propertize (concat spine-prefix spine-padding)
    'face face))))
    (forward-line 1))
    (when needs-full? (setf *vpi-did-full-indent?* t)))))

    (defun variable-pitch-hook-handler (s e l)
    (when (member this-command '(self-insert-command
    newline
    slime-autodoc-space
    indent-for-tab-command
    backward-delete-char-untabify
    yank))
    (variable-pitch-indent)))
    (push 'variable-pitch-hook-handler after-change-functions)