[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] master 027e7ed 012/108: Add variable dont-indent-if, so the user
From: |
Artur Malabarba |
Subject: |
[elpa] master 027e7ed 012/108: Add variable dont-indent-if, so the user can prevent indentation. |
Date: |
Wed, 25 Mar 2015 18:38:48 +0000 |
branch: master
commit 027e7eddc3e4a7bc2068106ce710fcf5ebd6e7aa
Author: Artur Malabarba <address@hidden>
Commit: Artur Malabarba <address@hidden>
Add variable dont-indent-if, so the user can prevent indentation.
Also add default values to it, to protect during autocomplete, company
complete, and yasnippet.
---
aggressive-indent.el | 72 +++++++++++++++++++++++++++++++++++++++++++++----
1 files changed, 66 insertions(+), 6 deletions(-)
diff --git a/aggressive-indent.el b/aggressive-indent.el
index ac3afee..5feefba 100644
--- a/aggressive-indent.el
+++ b/aggressive-indent.el
@@ -4,7 +4,7 @@
;; Author: Artur Malabarba <address@hidden>
;; URL: http://github.com/Bruce-Connor/aggressive-indent-mode
-;; Version: 0.1
+;; Version: 0.2
;; Package-Requires: ((emacs "24.1") (names "0.5") (cl-lib "0.5"))
;; Keywords: indent lisp maint tools
;; Prefix: aggressive-indent
@@ -80,6 +80,7 @@
;;
;;; Change Log:
+;; 0.2 - 2014/10/19 - Add variable `aggressive-indent-dont-indent-if', so the
user can prevent indentation.
;; 0.1 - 2014/10/15 - Release.
;;; Code:
@@ -119,6 +120,50 @@ commands will NOT be followed by a re-indent."
:type '(repeat symbol)
:package-version '(aggressive-indent . "0.1"))
+(defvar -internal-dont-indent-if
+ '((memq last-command aggressive-indent-protected-commands)
+ (region-active-p)
+ buffer-read-only
+ (null (buffer-modified-p)))
+ "List of forms which prevent indentation when they evaluate to non-nil.
+This is for internal use only. For user customization, use
+`aggressive-indent-dont-indent-if' instead.")
+
+(eval-after-load 'yasnippet
+ '(when (boundp 'yas--active-field-overlay)
+ (add-to-list 'aggressive-indent--internal-dont-indent-if
+ '(and
+ (overlayp yas--active-field-overlay)
+ (overlay-end yas--active-field-overlay))
+ 'append)))
+(eval-after-load 'company
+ '(when (boundp 'company-candidates)
+ (add-to-list 'aggressive-indent--internal-dont-indent-if
+ 'company-candidates)))
+(eval-after-load 'auto-complete
+ '(when (boundp 'ac-completing)
+ (add-to-list 'aggressive-indent--internal-dont-indent-if
+ 'ac-completing)))
+
+(defcustom dont-indent-if '()
+ "List of variables and functions to prevent aggressive indenting.
+This variable is a list where each element is a lisp form.
+As long as any one of these forms returns non-nil,
+aggressive-indent will not perform any indentation.
+
+See `aggressive-indent--internal-dont-indent-if' for usage examples."
+ :type '(repeat sexp)
+ :group 'aggressive-indent
+ :package-version '(aggressive-indent . "0.2"))
+
+(defvar -error-message
+ "One of the forms in `aggressive-indent-dont-indent-if' had the following
error, I've disabled it until you fix it: %S"
+ "Error message thrown by `aggressive-indent-dont-indent-if'.")
+
+(defvar -has-errored nil
+ "Keep track of whether `aggressive-indent-dont-indent-if' is throwing.
+This is used to prevent an infinite error loop on the user.")
+
(defun -softly-indent-defun ()
"Indent current defun unobstrusively.
Like `aggressive-indent-indent-defun', except do nothing if
@@ -126,15 +171,30 @@ mark is active (to avoid deactivaing it), or if buffer is
not
modified (to avoid creating accidental modifications).
Also, never throw errors nor messages.
-Meant for use in hooks. Interactively, use the other one."
- (unless (or (region-active-p)
- buffer-read-only
- (null (buffer-modified-p))
- (memq last-command protected-commands))
+Meant for use in hooks. Interactively, use the other one.
+Indentation is not performed if any of the forms in
+`dont-indent-if' evaluates to non-nil."
+ (unless (or (run-hook-wrapped
+ 'aggressive-indent--internal-dont-indent-if
+ #'eval)
+ (-run-user-hooks))
(ignore-errors
(cl-letf (((symbol-function 'message) #'ignore))
(indent-defun)))))
+(defun -run-user-hooks ()
+ "Safely run forms in `aggressive-indent-dont-indent-if'.
+If any of them errors out, we only report it once until it stops
+erroring again."
+ (and dont-indent-if
+ (condition-case er
+ (prog1 (eval (cons 'or dont-indent-if))
+ (setq -has-errored nil))
+ (error
+ (unless -has-errored
+ (setq -has-errored t)
+ (message -error-message er))))))
+
:autoload
(defun indent-defun ()
"Indent current defun.
- [elpa] master updated (714fc5b -> 90473ac), Artur Malabarba, 2015/03/25
- [elpa] master 3a0cc9b 001/108: Initial commit, Artur Malabarba, 2015/03/25
- [elpa] master b97643c 005/108: Shorten package description, Artur Malabarba, 2015/03/25
- [elpa] master d48181e 003/108: Readme, Artur Malabarba, 2015/03/25
- [elpa] master 29bbd66 004/108: Changed Lighter, Artur Malabarba, 2015/03/25
- [elpa] master 32387c7 006/108: Merge pull request #1 from purcell/patch-1, Artur Malabarba, 2015/03/25
- [elpa] master 7854cfc 007/108: Replace ’ by ', Artur Malabarba, 2015/03/25
- [elpa] master 82bf8bd 009/108: Merge pull request #2 from Silex/master, Artur Malabarba, 2015/03/25
- [elpa] master 4c2f34e 010/108: Add excluded mode, Artur Malabarba, 2015/03/25
- [elpa] master 3a4b76a 011/108: Merge branch 'dev', Artur Malabarba, 2015/03/25
- [elpa] master 027e7ed 012/108: Add variable dont-indent-if, so the user can prevent indentation.,
Artur Malabarba <=
- [elpa] master f23224a 014/108: Reactivate `electric-indent-mode'., Artur Malabarba, 2015/03/25
- [elpa] master 964bfae 016/108: Add yaml mode to excluded modes., Artur Malabarba, 2015/03/25
- [elpa] master 36abeb1 002/108: First Commit., Artur Malabarba, 2015/03/25
- [elpa] master 759f365 018/108: Merge pull request #8 from tuhdo/master, Artur Malabarba, 2015/03/25
- [elpa] master eaa8cee 013/108: Whitespace, Artur Malabarba, 2015/03/25
- [elpa] master 2e993b8 008/108: Remove trailing whitespace, Artur Malabarba, 2015/03/25
- [elpa] master a1429e5 019/108: Fix variable I forgot to namespace, Artur Malabarba, 2015/03/25
- [elpa] master 7cd4e57 015/108: Fix Version, Artur Malabarba, 2015/03/25
- [elpa] master aebe081 020/108: Improve css-mode support, Artur Malabarba, 2015/03/25
- [elpa] master 1c74518 023/108: Fix last-command -> this-command bug, Artur Malabarba, 2015/03/25