Skip to content

Commit

Permalink
Merge pull request #39 from tummychow/update-mode-declaration
Browse files Browse the repository at this point in the history
Split into local and global minor modes
  • Loading branch information
rrthomas authored Feb 18, 2018
2 parents 34f2e23 + d1e2543 commit 5263009
Showing 1 changed file with 16 additions and 16 deletions.
32 changes: 16 additions & 16 deletions dtrt-indent.el
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,22 @@ mode.
When dtrt-indent mode is enabled, the proper indentation offset
and `indent-tabs-mode' will be guessed for newly opened files and
adjusted transparently."
:lighter " dtrt-indent" :global t :group 'dtrt-indent)
:lighter " dtrt-indent"
:group 'dtrt-indent
(if dtrt-indent-mode
(if (and (featurep 'smie) (not (eq smie-grammar 'unset)))
(progn
(smie-config-guess)
(when dtrt-indent-run-after-smie
(dtrt-indent-try-set-offset)))
(dtrt-indent-try-set-offset))
(dtrt-indent-undo)))

;;;###autoload
(define-globalized-minor-mode dtrt-indent-global-mode dtrt-indent-mode
(lambda ()
(when (derived-mode-p 'prog-mode 'text-mode)
(dtrt-indent-mode))))

(defvar dtrt-indent-language-syntax-table
'((c/c++/java ("\"" 0 "\"" nil "\\\\.")
Expand Down Expand Up @@ -970,18 +985,6 @@ Indentation offset set with file variable; not adjusted")
nil))
))))

(defvar smie-grammar) ; in case smie is not available
(defun dtrt-indent-find-file-hook ()
"Try adjusting indentation offset when a file is loaded.
If the current mode uses SMIE, use `smie-config-guess'."
(when dtrt-indent-mode
(if (and (featurep 'smie) (not (eq smie-grammar 'unset)))
(progn
(smie-config-guess)
(when dtrt-indent-run-after-smie
(dtrt-indent-try-set-offset)))
(dtrt-indent-try-set-offset))))

(defun dtrt-indent-adapt ()
"Try adjusting indentation settings for the current buffer."
(interactive)
Expand Down Expand Up @@ -1034,9 +1037,6 @@ Disable dtrt-indent if offset explicitly set."
(ad-get-arg 0))
(setq dtrt-indent-explicit-tab-mode t))))

; Install global find-file-hook
(add-hook 'find-file-hook 'dtrt-indent-find-file-hook)

(autoload 'dtrt-indent-diagnosis "dtrt-indent-diag"
"Guess indentation for the current buffer and output diagnostics."
t)
Expand Down

0 comments on commit 5263009

Please sign in to comment.