Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Update for Emacs 24.

  • Loading branch information...
commit 8b2146c7d31dc690331ff0ad08a06b95a3b5bb1e 1 parent 2e8081d
Ross Lagerwall authored March 31, 2012
1  .gitignore
@@ -3,3 +3,4 @@ _backups
3 3
 %backup%~
4 4
 saveplace
5 5
 tramp
  6
+*~
259  column-marker.el
... ...
@@ -1,259 +0,0 @@
1  
-;;; column-marker.el --- Highlight certain character columns
2  
-;; 
3  
-;; Filename: column-marker.el
4  
-;; Description: Highlight certain character columns
5  
-;; Author: Rick Bielawski <rbielaws@i1.net>
6  
-;; Maintainer: Rick Bielawski <rbielaws@i1.net>
7  
-;; Created: Tue Nov 22 10:26:03 2005
8  
-;; Version: 
9  
-;; Last-Updated: Fri Jan 22 11:28:48 2010 (-0800)
10  
-;;           By: dradams
11  
-;;     Update #: 312
12  
-;; Keywords: tools convenience highlight
13  
-;; Compatibility: GNU Emacs 21, GNU Emacs 22, GNU Emacs 23
14  
-;; 
15  
-;; Features that might be required by this library:
16  
-;;
17  
-;;   None
18  
-;;
19  
-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
20  
-;; 
21  
-;;; Commentary: 
22  
-;; 
23  
-;; Highlights the background at a given character column.
24  
-;; 
25  
-;; Commands `column-marker-1', `column-marker-2', and
26  
-;; `column-marker-3' each highlight a given column (using different
27  
-;; background colors, by default).
28  
-;;
29  
-;; - With no prefix argument, each highlights the current column
30  
-;;   (where the cursor is).
31  
-;;
32  
-;; - With a non-negative numeric prefix argument, each highlights that
33  
-;;   column.
34  
-;;
35  
-;; - With plain `C-u' (no number), each turns off its highlighting.
36  
-;;
37  
-;; - With `C-u C-u', each turns off all column highlighting.
38  
-;;
39  
-;; If two commands highlight the same column, the last-issued
40  
-;; highlighting command shadows the other - only the last-issued
41  
-;; highlighting is seen.  If that "topmost" highlighting is then
42  
-;; turned off, the other highlighting for that column then shows
43  
-;; through.
44  
-;;
45  
-;; Examples:
46  
-;;
47  
-;; M-x column-marker-1 highlights the column where the cursor is, in
48  
-;; face `column-marker-1'.
49  
-;;
50  
-;; C-u 70 M-x column-marker-2 highlights column 70 in face
51  
-;; `column-marker-2'.
52  
-;;
53  
-;; C-u 70 M-x column-marker-3 highlights column 70 in face
54  
-;; `column-marker-3'.  The face `column-marker-2' highlighting no
55  
-;; longer shows.
56  
-;;
57  
-;; C-u M-x column-marker-3 turns off highlighting for column-marker-3,
58  
-;; so face `column-marker-2' highlighting shows again for column 70.
59  
-;;
60  
-;; C-u C-u M-x column-marker-1 (or -2 or -3) erases all column
61  
-;; highlighting.
62  
-;;
63  
-;; These commands use `font-lock-fontify-buffer', so syntax
64  
-;; highlighting (`font-lock-mode') must be turned on.  There might be
65  
-;; a performance impact during refontification.
66  
-;;
67  
-;;
68  
-;; Installation: Place this file on your load path, and put this in
69  
-;; your init file (`.emacs'):
70  
-;;
71  
-;; (require 'column-marker)
72  
-;;
73  
-;; Other init file suggestions (examples):
74  
-;;
75  
-;; ;; Highlight column 80 in foo mode.
76  
-;; (add-hook 'foo-mode-hook (lambda () (interactive) (column-marker-1 80)))
77  
-;;
78  
-;; ;; Use `C-c m' interactively to highlight with face `column-marker-1'.
79  
-;; (global-set-key [?\C-c ?m] 'column-marker-1)
80  
-;;
81  
-;;
82  
-;; Please report any bugs!
83  
-;;
84  
-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
85  
-;; 
86  
-;;; Change log:
87  
-;;
88  
-;; 2009/12/10 dadams
89  
-;;     column-marker-internal: Quote the face.  Thx to Johan Bockgård.
90  
-;; 2009/12/09 dadams
91  
-;;     column-marker-find: fset a symbol to the function, and return the symbol.
92  
-;; 2008/01/21 dadams
93  
-;;     Renamed faces by dropping suffix "-face".
94  
-;; 2006/08/18 dadams
95  
-;;     column-marker-create: Add newlines to doc-string sentences.
96  
-;; 2005/12/31 dadams
97  
-;;     column-marker-create: Add marker to column-marker-vars inside the defun,
98  
-;;       so it is done in the right buffer, updating column-marker-vars buffer-locally.
99  
-;;     column-marker-find: Corrected comment.  Changed or to progn for clarity.
100  
-;; 2005/12/29 dadams
101  
-;;     Updated wrt new version of column-marker.el (multi-column characters).
102  
-;;     Corrected stray occurrences of column-marker-here to column-marker-1.
103  
-;;     column-marker-vars: Added make-local-variable.
104  
-;;     column-marker-create: Changed positive to non-negative.
105  
-;;     column-marker-internal: Turn off marker when col is negative, not < 1.
106  
-;; 2005-12-29 RGB
107  
-;;     column-marker.el now supports multi-column characters.
108  
-;; 2005/11/21 dadams
109  
-;;     Combined static and dynamic. 
110  
-;;     Use separate faces for each marker.  Different interactive spec.
111  
-;; 2005/10/19 RGB
112  
-;;     Initial release of column-marker.el.
113  
-;;
114  
-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
115  
-;;
116  
-;; This program is free software; you can redistribute it and/or modify
117  
-;; it under the terms of the GNU General Public License as published by
118  
-;; the Free Software Foundation; either version 2, or (at your option)
119  
-;; any later version.
120  
-
121  
-;; This program is distributed in the hope that it will be useful,
122  
-;; but WITHOUT ANY WARRANTY; without even the implied warranty of
123  
-;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
124  
-;; GNU General Public License for more details.
125  
-
126  
-;; You should have received a copy of the GNU General Public License
127  
-;; along with this program; see the file COPYING.  If not, write to
128  
-;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth
129  
-;; Floor, Boston, MA 02110-1301, USA.
130  
-;;
131  
-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
132  
-;; 
133  
-;;; Code:
134  
-
135  
-;;;;;;;;;;;;;;;;;;;;;;
136  
-
137  
-
138  
-(defface column-marker-1 '((t (:background "gray")))
139  
-  "Face used for a column marker.  Usually a background color."
140  
-  :group 'faces)
141  
-
142  
-(defvar column-marker-1-face 'column-marker-1
143  
-    "Face used for a column marker.  Usually a background color.
144  
-Changing this directly affects only new markers.")
145  
-
146  
-(defface column-marker-2 '((t (:background "cyan3")))
147  
-  "Face used for a column marker.  Usually a background color."
148  
-  :group 'faces)
149  
-
150  
-(defvar column-marker-2-face 'column-marker-2
151  
-    "Face used for a column marker.  Usually a background color.
152  
-Changing this directly affects only new markers." )
153  
-
154  
-(defface column-marker-3 '((t (:background "orchid3")))
155  
-  "Face used for a column marker.  Usually a background color."
156  
-  :group 'faces)
157  
-
158  
-(defvar column-marker-3-face 'column-marker-3
159  
-    "Face used for a column marker.  Usually a background color.
160  
-Changing this directly affects only new markers." )
161  
-
162  
-(defvar column-marker-vars ()
163  
-  "List of all internal column-marker variables")
164  
-(make-variable-buffer-local 'column-marker-vars) ; Buffer local in all buffers.
165  
-
166  
-(defmacro column-marker-create (var &optional face)
167  
-  "Define a column marker named VAR.
168  
-FACE is the face to use.  If nil, then face `column-marker-1' is used."
169  
-  (setq face (or face 'column-marker-1))
170  
-  `(progn
171  
-     ;; define context variable ,VAR so marker can be removed if desired
172  
-     (defvar ,var ()
173  
-       "Buffer local. Used internally to store column marker spec.")
174  
-     ;; context must be buffer local since font-lock is 
175  
-     (make-variable-buffer-local ',var)
176  
-     ;; Define wrapper function named ,VAR to call `column-marker-internal'
177  
-     (defun ,var (arg)
178  
-       ,(concat "Highlight column with face `" (symbol-name face)
179  
-                "'.\nWith no prefix argument, highlight current column.\n"
180  
-                "With non-negative numeric prefix arg, highlight that column number.\n"
181  
-                "With plain `C-u' (no number), turn off this column marker.\n"
182  
-                "With `C-u C-u' or negative prefix arg, turn off all column-marker highlighting.")
183  
-       (interactive "P")
184  
-       (unless (memq ',var column-marker-vars) (push ',var column-marker-vars))
185  
-       (cond ((null arg)          ; Default: highlight current column.
186  
-              (column-marker-internal ',var (1+ (current-column)) ,face))
187  
-             ((consp arg)
188  
-              (if (= 4 (car arg))
189  
-                  (column-marker-internal ',var nil) ; `C-u': Remove this column highlighting.
190  
-                (dolist (var column-marker-vars)
191  
-                  (column-marker-internal var nil)))) ; `C-u C-u': Remove all column highlighting.
192  
-             ((and (integerp arg) (>= arg 0)) ; `C-u 70': Highlight that column.
193  
-              (column-marker-internal ',var (1+ (prefix-numeric-value arg)) ,face))
194  
-             (t           ; `C-u -40': Remove all column highlighting.
195  
-              (dolist (var column-marker-vars)
196  
-                (column-marker-internal var nil)))))))
197  
-
198  
-(defun column-marker-find (col)
199  
-  "Defines a function to locate a character in column COL.
200  
-Returns the function symbol, named `column-marker-move-to-COL'."
201  
-  (let ((fn-symb  (intern (format "column-marker-move-to-%d" col))))
202  
-    (fset `,fn-symb
203  
-          `(lambda (end)
204  
-             (let ((start (point)))
205  
-               (when (> end (point-max)) (setq end (point-max)))
206  
-
207  
-               ;; Try to keep `move-to-column' from going backward, though it still can.
208  
-               (unless (< (current-column) ,col) (forward-line 1))
209  
-
210  
-               ;; Again, don't go backward.  Try to move to correct column.
211  
-               (when (< (current-column) ,col) (move-to-column ,col))
212  
-
213  
-               ;; If not at target column, try to move to it.
214  
-               (while (and (< (current-column) ,col) (< (point) end)
215  
-                           (= 0 (+ (forward-line 1) (current-column)))) ; Should be bol.
216  
-                 (move-to-column ,col))
217  
-
218  
-               ;; If at target column, not past end, and not prior to start,
219  
-               ;; then set match data and return t.  Otherwise go to start
220  
-               ;; and return nil.
221  
-               (if (and (= ,col (current-column)) (<= (point) end) (> (point) start))
222  
-                   (progn (set-match-data (list (1- (point)) (point)))
223  
-                          t)            ; Return t.
224  
-                 (goto-char start)
225  
-                 nil))))                ; Return nil.
226  
-    fn-symb))
227  
-
228  
-(defun column-marker-internal (sym col &optional face)
229  
-  "SYM is the symbol for holding the column marker context.
230  
-COL is the column in which a marker should be set.
231  
-Supplying nil or 0 for COL turns off the marker.
232  
-FACE is the face to use.  If nil, then face `column-marker-1' is used."
233  
-  (setq face (or face 'column-marker-1))
234  
-  (when (symbol-value sym)   ; Remove any previously set column marker
235  
-    (font-lock-remove-keywords nil (symbol-value sym))
236  
-    (set sym nil))
237  
-  (when (or (listp col) (< col 0)) (setq col nil)) ; Allow nonsense stuff to turn off the marker
238  
-  (when col                             ; Generate a new column marker
239  
-    (set sym `((,(column-marker-find col) (0 ',face prepend t))))
240  
-    (font-lock-add-keywords nil (symbol-value sym) t))
241  
-  (font-lock-fontify-buffer))
242  
-
243  
-;; If you need more markers you can create your own similarly.
244  
-;; All markers can be in use at once, and each is buffer-local,
245  
-;; so there is no good reason to define more unless you need more
246  
-;; markers in a single buffer.
247  
-(column-marker-create column-marker-1 column-marker-1-face)
248  
-(column-marker-create column-marker-2 column-marker-2-face)
249  
-(column-marker-create column-marker-3 column-marker-3-face)
250  
-
251  
-;;;###autoload
252  
-(autoload 'column-marker-1 "column-marker" "Highlight a column." t)
253  
-
254  
-;;;;;;;;;;;;;;;;;;
255  
-
256  
-(provide 'column-marker)
257  
-
258  
-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
259  
-;;; column-marker.el ends here
963  dtrt-indent.el
... ...
@@ -1,963 +0,0 @@
1  
-;;; dtrt-indent.el --- Adapt to foreign indentation offsets
2  
-
3  
-;; Copyright (C) 2003, 2007, 2008 Julian Scheid
4  
-
5  
-;; Author: Julian Scheid <julians37@googlemail.com>
6  
-;; Version: 0.2.0
7  
-;; Keywords: convenience files languages c
8  
-
9  
-;; This file is free software; you can redistribute it and/or modify
10  
-;; it under the terms of the GNU General Public License as published by
11  
-;; the Free Software Foundation; either version 2, or (at your option)
12  
-;; any later version.
13  
-
14  
-;; This file is distributed in the hope that it will be useful,
15  
-;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16  
-;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  
-;; GNU General Public License for more details.
18  
-
19  
-;; You should have received a copy of the GNU General Public License
20  
-;; along with this software; see the file COPYING.  If not, write to
21  
-;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth
22  
-;; Floor, Boston, MA 02110-1301 USA
23  
-
24  
-;;; Commentary:
25  
-
26  
-;; A minor mode that guesses the indentation offset originally used
27  
-;; for creating source code files and transparently adjusts the
28  
-;; corresponding settings in Emacs, making it more convenient to edit
29  
-;; foreign files.
30  
-;;
31  
-;; This hooks into many major modes - c-mode, java-mode, shell-mode
32  
-;; and ruby-mode, to name but a few - and makes an educated guess on
33  
-;; which offset is appropriate by analyzing indentation levels in the
34  
-;; file.
35  
-;;
36  
-;; Heuristics are used to estimate the proper indentation offset and
37  
-;; therefore this system is not infallible, however adjustments will
38  
-;; only be made if the guess is considered reliable.  This way it
39  
-;; should leave you off no worse than before.
40  
-;;
41  
-;; To install,
42  
-;;   (require 'dtrt-indent)
43  
-;;   (dtrt-indent-mode 1)
44  
-;;
45  
-;; The default settings have been carefully chosen and tested to work
46  
-;; reliably on a wide range of source files.  However, if it doesn't
47  
-;; work for you they can be fine tuned using M-x customize-group
48  
-;; dtrt-indent
49  
-;;
50  
-;; There is more extensive information in the dtrt-indent info page
51  
-;; which you currently need to install manually.
52  
-;;
53  
-;; Improvements over guess-offset.el:
54  
-;;
55  
-;; - Whereas guess-offset only worked for C, C++ and Java files,
56  
-;;   dtrt-indent supports plenty of major modes (Shell script, Perl
57  
-;;   and Ruby are worth mentioning) and is easier to adapt to other
58  
-;;   languages.
59  
-;;
60  
-;; - dtrt-indent is now a minor mode and can be switched on and off,
61  
-;;   both globally and locally (the latter using a File Variable).
62  
-;;
63  
-;; - dtrt-indent is more precise in analyzing the syntax of source
64  
-;;   files, making its guess more accurate (it now ignores lines in
65  
-;;   comments, multi-line expressions, here documents and the like.)
66  
-;;
67  
-;; - dtrt-indent stops analyzing a source file after a customizable
68  
-;;   amount of lines, making it operate faster on large source files.
69  
-;;
70  
-;; - dtrt-indent leaves alone files that explicitly set the
71  
-;;   indentation offset with a File Variable.
72  
-;;
73  
-;; - dtrt-indent comes with diagnostic functions to help you
74  
-;;   understand what it does behind the scenes, adapt it to new
75  
-;;   languages or fine-tune its parameters.
76  
-;;
77  
-;; - The name of the script has been changed to better reflect its
78  
-;;   purpose.
79  
-;;
80  
-;; - The customization group is now a child of the convenience and
81  
-;;   files groups instead of the tools group.
82  
-;;
83  
-;; - The customization variables are named more sensibly and are
84  
-;;   better documented.
85  
-;;
86  
-;; - Documentation is improved and no longer confusingly refers to
87  
-;;   "tab width" instead of "indentation offset".
88  
-;;
89  
-;; Files not touched by dtrt-indent:
90  
-;;
91  
-;; - Files that specify the corresponding variable
92  
-;;   (e.g. c-basic-offset) as a File Variable.
93  
-;;
94  
-;; - Files that specify dtrt-indent-mode: 0 as a File Variable.
95  
-;;
96  
-;; - Files for which dtrt-indent-accept-file-function returns nil.
97  
-;;
98  
-;; - Files with a major mode that dtrt-indent doesn't hook into.
99  
-;;
100  
-;; - Files for which the indentation offset cannot be guessed
101  
-;;   reliably.
102  
-;;
103  
-;; Limitations:
104  
-;;
105  
-;; - dtrt-indent can't deal well with files that use variable
106  
-;;   indentation offsets, e.g. files that use varying indentation
107  
-;;   based on the outer construct.
108  
-;;
109  
-;; - dtrt-indent currently only supports a limited number of languages
110  
-;;   (major-modes).
111  
-;;
112  
-;; - dtrt-indent only guesses the indendation offset, not the
113  
-;;   indentation style.  For instance, it does not detect whether a
114  
-;;   C-like file uses hanging braces or not.
115  
-;;
116  
-;; - dtrt-indent can't deal well with files that mix hard tabs with
117  
-;; - spaces for indentation.
118  
-;;
119  
-;; TODO:
120  
-;;
121  
-;; - verbose and diagnostics messages
122  
-;; - make sure variable documentation match their function
123  
-;; - make sure defaults are sensible
124  
-;; - complete info page
125  
-;; - bulk (real world) tests
126  
-;; - functional tests
127  
-;; - unit tests
128  
-
129  
-;;; Change log:
130  
-
131  
-;; Revision 0.2.0 (2008-03-25)
132  
-;; Major rewrite
133  
-;; Name change from guess-offset.el to dtrt-indent.el
134  
-;;
135  
-;; Revision 0.1.2 (2007-02-02)
136  
-;; Minor documentation cleanups
137  
-;; Added link to cc-guess.el
138  
-;; Applied two patches courtesy of Michael Ernst <mernst@alum.mit.edu>:
139  
-;; (1) The problem is that you wrote
140  
-;;     (- 1 bracket-level)
141  
-;;     where you probably meant
142  
-;;     (- bracket-level 1)
143  
-;; (2) The documentation for `beginning-of-buffer' says
144  
-;;     Don't use this command in Lisp programs!
145  
-;;     (goto-char (point-min)) is faster and avoids clobbering the mark.
146  
-;;
147  
-;; Revision 0.1.1 (2003-??-??)
148  
-;; Initial version
149  
-
150  
-;;; Code:
151  
-
152  
-;;;###autoload
153  
-(define-minor-mode dtrt-indent-mode
154  
-  "Toggle dtrt-indent mode.
155  
-With no argument, this command toggles the mode.  Non-null prefix
156  
-argument turns on the mode.  Null prefix argument turns off the
157  
-mode.
158  
-
159  
-When dtrt-indent mode is enabled, the proper indentation
160  
-offset will be guessed for newly opened files and adjusted
161  
-transparently."
162  
-  :global t :group 'dtrt-indent)
163  
-
164  
-(defvar dtrt-indent-language-syntax-table
165  
-  '((c/c++/java ("\""                    0   "\""       nil "\\\\.")
166  
-                ("'"                     0   "'"        nil "\\\\.")
167  
-                ("[/][*]"                0   "[*][/]"   nil)
168  
-                ("[/][/]"                0   "$"        nil)
169  
-                ("("                     0   ")"        t)
170  
-                ("\\["                   0   "\\]"      t))
171  
-
172  
-    (perl       ("\""                    0   "\""       nil "\\\\.")
173  
-                ("'"                     0   "'"        nil "\\\\.")
174  
-                ("[#]"                   0   "$"        nil)
175  
-                ("("                     0   ")"        t)
176  
-                ("\\["                   0   "\\]"      t))
177  
-
178  
-    (ruby       ("\""                    0   "\""       nil "\\.")
179  
-                ("'"                     0   "'"        nil "\\.")
180  
-                ("#"                     0   "$"        nil)
181  
-                ("("                     0   ")"        t)
182  
-                ("\\["                   0   "\\]"      t)
183  
-                ("{"                     0   "}"        t))
184  
-
185  
-    (ada        ("\""                    0   "\""       nil "\\.")
186  
-                ("--"                    0   "$"        nil)
187  
-                ("("                     0   ")"        t)
188  
-                ("\\["                   0   "\\]"      t)
189  
-                ("{"                     0   "}"        t))
190  
-
191  
-;;  python-mode comes with offset guessing
192  
-;;  (python     ("\"\"\""                0   "\"\"\""   nil "\\.")
193  
-;;              ("\""                    0   "\""       nil "\\.")
194  
-;;              ("'"                     0   "'"        nil "\\.")
195  
-;;              ("#"                     0   "$"        nil)
196  
-;;              ("("                     0   ")"        t)
197  
-;;              ("\\["                   0   "\\]"      t)
198  
-;;              ("{"                     0   "}"        t))
199  
-
200  
-    (shell      ("\""                    0   "\""       nil "\\.")
201  
-                ("'"                     0   "'"        nil "\\.")
202  
-                ("[<][<]\\\\?\\([^ \t]+\\)"   1   "^\\1"     nil)
203  
-                ("("                     0   ")"        t)
204  
-                ("\\["                   0   "\\]"      t)))
205  
-
206  
-  "A list of syntax tables for supported languages.
207  
-
208  
-Each entry in this list is of the form
209  
-
210  
-   (SYMBOL SYNTAX-ENTRY [SYNTAX-ENTRY [...]])
211  
-
212  
-where SYMBOL is used to identify the language in
213  
-question and SYNTAX-ENTRY is in format
214  
-
215  
-   (BEGIN-REGEXP NUM-GROUPS END-REGEXP RECURSIVE-P SKIP-REGEXP)
216  
-
217  
-BEGIN-REGEXP is a regular expression matching the beginning of
218  
-the syntax construct in question.  NUM-GROUPS indicates how many
219  
-groups there are in BEGIN-REGEXP to be substituted in END-REGEXP.
220  
-
221  
-END-REGEXP is a regular expression matching the end of the syntax
222  
-construct in question.  It can refer back to one group in
223  
-BEGIN-REGEXP using \1. Currently only one group is supported (\2
224  
-cannot be used.)
225  
-
226  
-RECURSIVE-P indicates whether other syntax constructs can be
227  
-nested within this construct.  RECURSIVE-P is usually false for
228  
-comment and constant constructs, such as strings, and usually
229  
-true for bracketing constructs.
230  
-
231  
-SKIP-REGEXP is a regular expression that, if matches, means that
232  
-END-REGEXP is ignored for that location.  This can be used to
233  
-prevent an escaped quote from being interpreted as the closing
234  
-quote, for example.")
235  
-
236  
-(defvar dtrt-indent-hook-mapping-list
237  
-;;   Mode            Hook                  Syntax        Variable
238  
-  '((c-mode          c/c++/java    c-basic-offset)       ; C
239  
-    (c++-mode        c/c++/java    c-basic-offset)       ; C++
240  
-    (java-mode       c/c++/java    c-basic-offset)       ; Java
241  
-    (jde-mode        c/c++/java    c-basic-offset)       ; Java (JDE)
242  
-    (javascript-mode c/c++/java    c-basic-offset)       ; JavaScript
243  
-    (objc-mode       c/c++/java    c-basic-offset)       ; Objective C
244  
-    (php-mode        c/c++/java    c-basic-offset)       ; PHP
245  
-    (perl-mode       perl          perl-indent-level)    ; Perl
246  
-;;  (python-mode     python        py-indent-offset)     ; Python
247  
-    (ruby-mode       ruby          ruby-indent-level)    ; Ruby
248  
-    (ada-mode        ada           ada-indent)           ; Ada
249  
-    (sh-mode         shell         sh-basic-offset)      ; Shell Script
250  
-    (pascal-mode     pascal        pascal-indent-level)) ; Pascal
251  
-   "A mapping from hook variables to language types.")
252  
-
253  
-;;-----------------------------------------------------------------
254  
-;; Customization Definitions:
255  
-
256  
-(defgroup dtrt-indent nil
257  
-  "Transparently adapt to foreign indentation offsets."
258  
-  :version "22.0"
259  
-  :group 'files
260  
-  :group 'convenience)
261  
-
262  
-;;;###autoload
263  
-(defcustom dtrt-indent-mode nil
264  
-  "Toggle adaptive indentation mode.
265  
-Setting this variable directly does not take effect;
266  
-use either \\[customize] or the function `dtrt-indent-mode'."
267  
-  :set #'(lambda (symbol value) (funcall symbol (or value 0)))
268  
-  :initialize 'custom-initialize-default
269  
-  :version "22.0"
270  
-  :type    'boolean
271  
-  :group   'dtrt-indent
272  
-  :require 'dtrt-indent)
273  
-
274  
-(defcustom dtrt-indent-verbosity 1
275  
-  "*Verbosity level.
276  
-
277  
-How much dtrt-indent should tell you about what it's doing.  If
278  
-this is 1, the default, dtrt-indent will only let you know when
279  
-it adjusts the indentation offset but will be silent otherwise.
280  
-By setting this to 2 it will also tell you why it didn't adjust
281  
-the offset.  You might want to try this as a first measure if
282  
-you're unhappy with dtrt-indent's actions.  A setting of 3 will
283  
-output lots of diagnostic information.  Finally, a setting of 0
284  
-keeps dtrt-indent of ever outputting anything."
285  
-  :type '(choice (const :tag "Silent" 0)
286  
-                 (const :tag "Normal" 1)
287  
-                 (const :tag "Verbose" 2)
288  
-                 (const :tag "Diagnostics" 3))
289  
-  :tag "Verbosity"
290  
-  :group 'dtrt-indent)
291  
-
292  
-(defcustom dtrt-indent-require-confirmation-flag nil
293  
-  "*Non-nil means to ask for confirmation before making adjustments.
294  
-
295  
-Whether dtrt-indent asks for confirmation whenever it is about to
296  
-make any adjustments.  By default, adjustments are made without
297  
-your explicit consent because dtrt-indent is already quite
298  
-conservative and tries to 'do the right thing', adjustments can
299  
-be undone easily, and they aren't harmful in the first place.
300  
-However, if you feel like it's doing things behind your back
301  
-you should enable this setting."
302  
-  :type 'boolean
303  
-  :tag "Require Confirmation"
304  
-  :group 'dtrt-indent)
305  
-
306  
-(defcustom dtrt-indent-min-relevant-lines 2
307  
-  "*Minimum number of relevant lines required for a guess to be made.
308  
-
309  
-This check is in place because with a very low number of lines
310  
-that can be analyzed the chances of a wrong guess are rather
311  
-high because the sample size is so small.  If you are getting
312  
-false positives with small files - i.e. the wrong offset is guessed
313  
-- you might want to increase this setting.  On the other hand, if
314  
-you are getting false negatives on small files - i.e. no guess is
315  
-made on a small file - you might want to decrease it."
316  
-  :type 'integer
317  
-  :tag "Minimum Number Of Relevant Lines"
318  
-  :group 'dtrt-indent)
319  
-
320  
-(defcustom dtrt-indent-max-relevant-lines 500
321  
-  "*Maximum number of relevant lines to be considered in analysis.
322  
-
323  
-This setting is meant to prevent dtrt-indent from spending large
324  
-amounts of time on analyzing large source files.  In general, the
325  
-higher this setting, the more accurate the guess will be but the
326  
-more time dtrt-indent will consume when opening files.  If you
327  
-have a fast box you might want to consider increasing this
328  
-number.  On the other hand, if you find that dtrt-indent
329  
-introduces a noticable delay when opening files you might want
330  
-to decrease it."
331  
-  :type 'integer
332  
-  :tag "Maximum Number Of Relevant Lines"
333  
-  :group 'dtrt-indent)
334  
-
335  
-(defcustom dtrt-indent-min-quality 80.0
336  
-  "*Minimum quality for an indentation offset to be accepted.
337  
-
338  
-Percentage (0-100) of lines that are indented by a non-zero
339  
-amount of spaces divisible by a given offset required for that
340  
-offset to be eligible for guessing.  A value of 80 means that for
341  
-instance, an indentation level of 4 will only be guessed if at
342  
-least 80% of all lines are indented by an offset divisible by 4.
343  
-
344  
-This setting essentially controls how lenient or conservative
345  
-dtrt-indent operates.  If you are getting false positives -
346  
-i.e. guess-offset guesses the wrong offset - you might want to
347  
-increase this setting.  On the other hand, if you are getting
348  
-false negatives - i.e. guess-offset refuses to adjust the offset
349  
-- you might want to decrease it."
350  
-  :type 'float
351  
-  :tag "Minimum Number Of Matching Lines"
352  
-  :group 'dtrt-indent)
353  
-
354  
-(defcustom dtrt-indent-min-indent-superiority 100.0
355  
-  "*Minimum percentage the best guess needs to be better than second best.
356  
-
357  
-The percentage (0-100, but higher values than 100 are possible)
358  
-that the number of lines matching the best guess must be higher
359  
-than the number of lines matching the second best guess in order
360  
-for dtrt-indent to adjust the offset.  For example, a value of
361  
-100 means that there must be twice as many lines matching the
362  
-best guess than the number of lines matching the second best
363  
-guess.
364  
-
365  
-This check is in place to avoid a good guess to be accepted if
366  
-there is another, similarly good guess, because in that situation
367  
-there is ambiguity and no single reliable guess.  If you are
368  
-getting false positives - i.e. dtrt-indent guesses the wrong
369  
-offset - you might want to increase this setting.  On the other
370  
-hand, if you are getting false negatives - i.e. dtrt-indent
371  
-refuses to adjust the offset - you might want to decrease it."
372  
-  :type 'float
373  
-  :tag "Minimum Superiority Of Best Guess"
374  
-  :group 'dtrt-indent)
375  
-
376  
-(defcustom dtrt-indent-min-soft-tab-superiority 300.0
377  
-  "*Minimum percentage soft-tab lines need to outnumber hard-tab ones.
378  
-
379  
-TBD"
380  
-  :type 'float
381  
-  :tag "Minimum Superiority Of Soft Tabs"
382  
-  :group 'dtrt-indent)
383  
-
384  
-(defcustom dtrt-indent-min-hard-tab-superiority 300.0
385  
-  "*Minimum percentage hard-tab lines need to outnumber soft-tab ones.
386  
-
387  
-TBD"
388  
-  :type 'float
389  
-  :tag "Minimum Superiority Of Hard Tabs"
390  
-  :group 'dtrt-indent)
391  
-
392  
-(defcustom dtrt-indent-max-merge-deviation 20.0
393  
-  "*Minimum difference between offsets divisible without remainder.
394  
-
395  
-The percentage of difference in the number of lines that are
396  
-matched by two guessed offsets where the larger offset is
397  
-divisible by the smaller without remainder for the smaller offset
398  
-to be discarded.
399  
-
400  
-This setting is in place because without it, in a file with 1000
401  
-lines matching an offset of 4, all of those 1000 lines are also
402  
-matching an offset of 2 and a number of stray lines whose offset
403  
-is divisible by 2 but not by 4 would confuse dtrt-indent to treat
404  
-the smaller offset as the better guess.  By discarding the
405  
-smaller offset with some tolerance, this problem is avoided.
406  
-
407  
-If you notice that often, sub-offsets are wrongly guessed (e.g. 8
408  
-would be the proper offset but 4 is guessed, or 6 would be
409  
-correct but 3 is guessed) you might want to decrease this
410  
-setting.  On the other hand, if super-offsets are guessed (e.g. 4
411  
-would be appropriate, but 8 is guessed) you might want to
412  
-increase it."
413  
-  :type 'float
414  
-  :tag "Maximum Deviation For Sub-Offset Merging"
415  
-  :group 'dtrt-indent)
416  
-
417  
-(defcustom dtrt-indent-ignore-single-chars-flag nil
418  
-  "*Non-nil means ignore lines containing only a single character.
419  
-
420  
-Whether to treat lines that contain only a single non-whitespace
421  
-character as irrelevant for the analysis.  Set this to t in to
422  
-prevent hanging braces etc. from skewing the results.  Set it to
423  
-nil if you are dealing with source files whose indentation level
424  
-isn't reliably guessed without those lines."
425  
-  :type 'boolean
426  
-  :tag "Ignore Single-Character Lines"
427  
-  :group 'dtrt-indent)
428  
-
429  
-(defcustom dtrt-indent-min-matching-indentations 1
430  
-  "*Minimum number of distinct levels for an offset to be eligible.
431  
-
432  
-The minimum number of distinct, non-zero indentation levels
433  
-matching a given offset required to be present in a file for that
434  
-offset to be eligible for guessing.  A value of 2 means that for
435  
-instance, an indentation level of 4 will only be guessed if some
436  
-lines are indented at 4 spaces and some at 8; or if some lines
437  
-are indented at 12 spaces and some at 20; but not if some lines
438  
-are indented at 4 spaces but there are no other lines indented at
439  
-an offset divisible by 4.
440  
-
441  
-The default value of 1 effectively disables any such requirement.
442  
-If you are getting false positives, you might want to set this to
443  
-a higher value such as 2.  However, a value of 2 means that the
444  
-offset won't be guessed for files containing only 'flat'
445  
-constructs"
446  
-  :type 'integer
447  
-  :tag "Minimum Depth"
448  
-  :group 'dtrt-indent)
449  
-
450  
-(defcustom dtrt-indent-min-offset 2
451  
-  "*Minimum indentation offset that can be guessed.
452  
-
453  
-You usually don't want to tinker with this - setting it to a
454  
-higher value than 2 means that the rather common offset of 2 will
455  
-no longer be guessed.  Setting it to 1 will likely screw up
456  
-dtrt-indent algorithms because every line in every source code
457  
-matches that indentation level."
458  
-  :type 'integer
459  
-  :tag "Minimum Guessed Indentation Offset"
460  
-  :group 'dtrt-indent)
461  
-
462  
-(defcustom dtrt-indent-max-offset 8
463  
-  "*Maximum indentation offset that can be guessed.
464  
-
465  
-You usually don't want to tinker with this - setting it to a
466  
-lower value than 8 means that the (unfortunately) rather common
467  
-indentation offset of 8 will no longer be guessed.  Setting it to
468  
-a higher value than 8 should not be harmful, but source files
469  
-using more than 8 spaces per indentation level are very rare."
470  
-  :type 'integer
471  
-  :tag "Maximum Guessed Indentation Offset"
472  
-  :group 'dtrt-indent)
473  
-
474  
-(defcustom dtrt-indent-accept-file-function (lambda (filename) t)
475  
-  "*Acceptor determining which files are analyzed.
476  
-
477  
-This function will be called for every file dtrt-indent would
478  
-normally analyze with one argument, the file name.  Only if it
479  
-returns a non-nil value analysis will be performed on the file.
480  
-
481  
-By default, all files are analyzed."
482  
-  :type 'function
483  
-  :tag "Analysed File Inclusion Function"
484  
-  :group 'dtrt-indent)
485  
-
486  
-(defvar dtrt-indent-original-indent)
487  
-(make-variable-buffer-local
488  
- 'dtrt-indent-original-indent)
489  
-
490  
-(defvar dtrt-indent-mode-line-info)
491  
-(make-variable-buffer-local
492  
- 'dtrt-indent-mode-line-info)
493  
-
494  
-(defvar dtrt-indent-explicit-offset)
495  
-(make-variable-buffer-local
496  
- 'dtrt-indent-explicit-offset)
497  
-
498  
-(defvar dtrt-indent-explicit-tab-mode)
499  
-(make-variable-buffer-local
500  
- 'dtrt-indent-explicit-tab-mode)
501  
-
502  
-(defun dtrt-indent--replace-in-string (haystack
503  
-                                        needle-regexp
504  
-                                        replacement)
505  
-  "Replace every match in string by constant replacement.
506  
-Returns HAYSTACK with every match of NEEDLE-REGEXP replaced by
507  
-REPLACEMENT."
508  
-  (if (string-match needle-regexp haystack)
509  
-      (concat (substring haystack 0 (match-beginning 0))
510  
-              replacement
511  
-              (substring haystack (match-end 0)))
512  
-    haystack))
513  
-
514  
-
515  
-(defun dtrt-indent--skip-to-end-of-match (end-regex
516  
-                                           skip-regex
517  
-                                           syntax-regex-pairs
518  
-                                           multi-line)
519  
-  "Place point at the end of the current match.
520  
-END-REGEX is a regular expression matching the end.  If
521  
-SKIP-REGEX matches though, END-REGEX is ignored.
522  
-SYNTAX-REGEX-PAIRS is a list of syntax entries as described for
523  
-`dtrt-indent-language-syntax-table'.  MULTI-LINE, if false,
524  
-constrains the search to the current line."
525  
-  (let* ((index-offset 1)
526  
-         end-index
527  
-         skip-index
528  
-         (regexp
529  
-          (mapconcat
530  
-           (lambda (el) (concat "\\(" el "\\)"))
531  
-           (append (when end-regex
532  
-                     (setq end-index index-offset)
533  
-                     (setq index-offset (1+ index-offset))
534  
-                     (list end-regex))
535  
-                   (when skip-regex
536  
-                     (setq skip-index index-offset)
537  
-                     (setq index-offset (1+ index-offset))
538  
-                     (list skip-regex))
539  
-                   (mapcar (lambda (x) (car x))
540  
-                           syntax-regex-pairs))
541  
-           "\\|")))
542  
-    (while
543  
-        (and
544  
-         (re-search-forward regexp
545  
-                            (unless multi-line
546  
-                              (save-excursion (end-of-line) (point))) t)
547  
-         (let ((match-index 1)
548  
-               (match-count (/ (length (match-data)) 2)))
549  
-           (while (and (<= match-index match-count)
550  
-                       (null (match-beginning match-index)))
551  
-             (setq match-index (1+ match-index)))
552  
-           (cond
553  
-            ((eq match-index end-index) nil)
554  
-            ((eq match-index skip-index) t)
555  
-            (t
556  
-             (let ((matching-syntax-entry
557  
-                    (let ((match-count (- match-index index-offset))
558  
-                          (syntax-regex-iterator syntax-regex-pairs))
559  
-                      (while (> match-count
560  
-                                (nth 1 (car syntax-regex-iterator)))
561  
-                        (setq match-count
562  
-                              (- match-count
563  
-                                 (nth 1 (car syntax-regex-iterator)) 1))
564  
-                        (setq syntax-regex-iterator
565  
-                              (cdr syntax-regex-iterator)))
566  
-                      (car syntax-regex-iterator))))
567  
-               (dtrt-indent--skip-to-end-of-match
568  
-                (if (> (nth 1 matching-syntax-entry) 0)
569  
-                    (dtrt-indent--replace-in-string
570  
-                     (nth 2 matching-syntax-entry)
571  
-                     "[\\][1]" (regexp-quote
572  
-				(match-string-no-properties
573  
-				 (1+ match-index))))
574  
-                  (nth 2 matching-syntax-entry))
575  
-                (nth 4 matching-syntax-entry)
576  
-                (when (nth 3 matching-syntax-entry) syntax-regex-pairs)
577  
-                t)
578  
-               t))))))))
579  
-
580  
-(defun dtrt-indent--for-each-indentation (language func user-data)
581  
-  "Call a function for each indentation found.
582  
-LANGUAGE is used to lookup a syntax table for excluding lines
583  
-from the process.  For each line not excluded, FUNC is called
584  
-with USER-DATA as its argument and with point on the first
585  
-non-whitespace character of the line."
586  
-  (save-excursion
587  
-    (goto-char (point-min))
588  
-    (while (and (re-search-forward "^[ \t]*" nil t)
589  
-                (funcall func user-data)
590  
-                (progn
591  
-                  (dtrt-indent--skip-to-end-of-match
592  
-                   nil
593  
-                   nil
594  
-                   (cdr
595  
-                    (assoc language
596  
-                           dtrt-indent-language-syntax-table))
597  
-                   nil)
598  
-                  (beginning-of-line)
599  
-                  (let ((here (point)))
600  
-                    (forward-line)
601  
-                    (not (eq here (point)))))))))
602  
-
603  
-(defun dtrt-indent--calc-histogram (language)
604  
-  "Calculate an indendation histogram.
605  
-
606  
-The histogram is calculated for the current buffer using LANGUAGE
607  
-to determine which lines to exclude from the histogram."
608  
-  (let ((histogram (make-hash-table))
609  
-        (hard-tab-line-count 0)
610  
-        (soft-tab-line-count 0))
611  
-
612  
-    (dtrt-indent--for-each-indentation
613  
-     language
614  
-     (lambda (histogram-and-count)
615  
-       (when (and (> (current-column) 0)
616  
-                  (not (looking-at "$"))
617  
-                  (or (not dtrt-indent-ignore-single-chars-flag)
618  
-                      (save-excursion
619  
-                        (forward-char)
620  
-                        (not (looking-at "[ \t]*$")))))
621  
-         (puthash (current-column)
622  
-                  (1+ (gethash (current-column)
623  
-                               (car histogram-and-count) 0))
624  
-                  (car histogram-and-count))
625  
-         (beginning-of-line)
626  
-         (if (looking-at "[\t]+")
627  
-             (setq hard-tab-line-count (1+ hard-tab-line-count))
628  
-           (setq soft-tab-line-count (1+ soft-tab-line-count)))
629  
-         (setcdr histogram-and-count (1+ (cdr histogram-and-count))))
630  
-       (< (cdr histogram-and-count)
631  
-          dtrt-indent-max-relevant-lines))
632  
-     (cons histogram 0))
633  
-    (let ((histogram-list '()) (total-lines 0))
634  
-      (maphash (lambda (key value)
635  
-                 (setq histogram-list (append histogram-list
636  
-                                              (list (list key value))))
637  
-                 (setq total-lines (+ total-lines value)))
638  
-               histogram)
639  
-      (list histogram-list
640  
-            total-lines
641  
-            hard-tab-line-count
642  
-            soft-tab-line-count))))
643  
-
644  
-(defun dtrt-indent--analyze-histogram-try-offset (try-offset
645  
-                                                   histogram
646  
-                                                   total-lines)
647  
-  "Return match information for the given offset.
648  
-TRY-OFFSET is the offset to try, HISTOGRAM is the previously
649  
-calculated indentation histogram, TOTAL-LINES is the total number
650  
-of lines for which the histogram was calculated.
651  
-
652  
-Returns a list in the format (TRY-OFFSET, PERCENTAGE,
653  
-MATCHING-INDENTATIONS, REJECT-REASON) where TRY-OFFSET is the
654  
-offset that was passed in as the first argument, PERCENTAGE is
655  
-the percentage of lines (0..1) with indentation levels that are a
656  
-multiple of TRY-OFFSET, MATCHING-INDENTATIONS is the number of
657  
-distinct indentation levels found that are a multiple of
658  
-TRY-OFFSET, and REJECT-REASON, if non-nil, is a string explaining
659  
-why TRY-OFFSET should be rejected."
660  
-  (let ((total-matching-lines 0)
661  
-        (matching-indentations 0))
662  
-    (dolist (histogram-entry histogram)
663  
-      (when (eq 0 (mod (nth 0 histogram-entry) try-offset))
664  
-        (setq total-matching-lines (+ total-matching-lines
665  
-                                      (nth 1 histogram-entry)))
666  
-        (setq matching-indentations (1+ matching-indentations))))
667  
-    (list try-offset
668  
-          (/ (float total-matching-lines) total-lines)
669  
-          matching-indentations
670  
-          (cond
671  
-           ((< matching-indentations
672  
-               dtrt-indent-min-matching-indentations)
673  
-            (format "\
674  
-rejected: too few distinct matching offsets (%d required)"
675  
-                    dtrt-indent-min-matching-indentations))
676  
-           (t
677  
-            nil)))))
678  
-
679  
-(defun dtrt-indent--analyze (histogram-and-total-lines)
680  
-  "Analyze the histogram.
681  
-
682  
-HISTOGRAM-AND-TOTAL-LINES is a tuple with the first item being
683  
-the histogram, the second item being the total number of lines
684  
-considered in the histogram.
685  
-
686  
-Returns a map with the following entries:
687  
-
688  
-TBD"
689  
-  (let* ((analysis
690  
-          (let ((try-offset dtrt-indent-min-offset)
691  
-                unsorted-analysis)
692  
-            (while (<= try-offset dtrt-indent-max-offset)
693  
-              (setq
694  
-               unsorted-analysis
695  
-               (append unsorted-analysis
696  
-                       (list (dtrt-indent--analyze-histogram-try-offset
697  
-                              try-offset
698  
-                              (nth 0 histogram-and-total-lines)
699  
-                              (nth 1 histogram-and-total-lines)))))
700  
-              (setq try-offset (1+ try-offset)))
701  
-            (sort unsorted-analysis (lambda (x y) (> (nth 1 x)
702  
-                                                     (nth 1 y))))))
703  
-         (analysis-iterator analysis))
704  
-
705  
-    (while analysis-iterator
706  
-      (let ((analysis-entry (car analysis-iterator)))
707  
-        (dolist (other-analysis-entry (cdr analysis-iterator))
708  
-
709  
-          (let ((deviation (abs (- (nth 1 other-analysis-entry)
710  
-                                   (nth 1 analysis-entry)))))
711  
-            (when (and (not (nth 3 analysis-entry))
712  
-                       (eq 0 (mod (car other-analysis-entry)
713  
-                                  (car analysis-entry)))
714  
-                       (> dtrt-indent-max-merge-deviation
715  
-                          (* 100.0 deviation)))
716  
-              (setcdr
717  
-               (cddr analysis-entry)
718  
-               (list
719  
-                (format "\
720  
-merged with offset %s (%.2f%% deviation, limit %.2f%%)"
721  
-                        (nth 0 other-analysis-entry)
722  
-                        (* 100.0 deviation)
723  
-                        dtrt-indent-max-merge-deviation)))))))
724  
-      (setq analysis-iterator (cdr analysis-iterator)))
725  
-
726  
-    (let (best-guess second-best-guess)
727  
-      (dolist (guess analysis)
728  
-        (cond
729  
-         ((and (null best-guess)
730  
-               (null (nth 3 guess)))
731  
-          (setq best-guess guess))
732  
-         ((and (null second-best-guess)
733  
-               (null (nth 3 guess)))
734  
-          (setq second-best-guess guess))))
735  
-
736  
-      (let* ((confidence
737  
-      (if best-guess
738  
-          (- (nth 1 best-guess)
739  
-             (if second-best-guess
740  
-                 (* 2.0 (expt (/ (nth 1 second-best-guess) 2.0) 2))
741  
-               0))
742  
-        0))
743  
-             (total-lines (nth 1 histogram-and-total-lines))
744  
-             (hard-tab-percentage (if (> total-lines 0)
745  
-                                      (/ (float (nth 2 histogram-and-total-lines))
746  
-                                         total-lines)
747  
-                                    0))
748  
-             (soft-tab-percentage (if (> total-lines 0)
749  
-                                      (/ (float (nth 3 histogram-and-total-lines))
750  
-                                         total-lines)
751  
-                                    0))
752  
-             (change-indent-tabs-mode)
753  
-             (indent-tabs-mode-setting)
754  
-             (rejected
755  
-             (cond
756  
-              ((null best-guess)
757  
-               "no best guess")
758  
-              ((< (* 100.0 (nth 1 best-guess))
759  
-                  dtrt-indent-min-quality)
760  
-               (format "best guess below minimum quality (%f < %f)"
761  
-                       (* 100.0 (nth 1 best-guess))
762  
-                       dtrt-indent-min-quality))
763  
-              ((and second-best-guess
764  
-                    (< (- (/ (* 100.0 (nth 1 best-guess))
765  
-                             (nth 1 second-best-guess))
766  
-                          100)
767  
-                       dtrt-indent-min-indent-superiority))
768  
-               "best guess not much better than second best guess"))))
769  
-
770  
-        (cond
771  
-         ((or (= 0 hard-tab-percentage)
772  
-              (>= (/ soft-tab-percentage
773  
-                     hard-tab-percentage)
774  
-                  (+ 1.0 (/ dtrt-indent-min-soft-tab-superiority 100.0))))
775  
-         (setq change-indent-tabs-mode t)
776  
-         (setq indent-tabs-mode-setting nil))
777  
-
778  
-         ((or (= 0 soft-tab-percentage)
779  
-              (>= (/ hard-tab-percentage
780  
-                     soft-tab-percentage)
781  
-                  (+ 1.0 (/ dtrt-indent-min-hard-tab-superiority 100.0))))
782  
-         (setq change-indent-tabs-mode t)
783  
-         (setq indent-tabs-mode-setting t)))
784  
-
785  
-        (list (cons :histogram (car histogram-and-total-lines))
786  
-              (cons :total-lines total-lines)
787  
-              (cons :analysis analysis)
788  
-              (cons :best-guess best-guess)
789  
-              (cons :second-best-guess second-best-guess)
790  
-              (cons :hard-tab-lines (nth 2 histogram-and-total-lines) )
791  
-              (cons :hard-tab-percentage hard-tab-percentage)
792  
-              (cons :soft-tab-lines (nth 3 histogram-and-total-lines) )
793  
-              (cons :soft-tab-percentage soft-tab-percentage)
794  
-              (cons :change-indent-tabs-mode change-indent-tabs-mode)
795  
-              (cons :indent-tabs-mode-setting indent-tabs-mode-setting)
796  
-              (cons :rejected rejected)
797  
-              (cons :confidence confidence))))))
798  
-
799  
-(defun dtrt-indent-try-set-offset ()
800  
-  "Try adjusting the current buffer's indentation offset."
801  
-  (let ((language-and-variable
802  
-         (cdr (assoc major-mode
803  
-                     dtrt-indent-hook-mapping-list))))
804  
-
805  
-    (when language-and-variable
806  
-
807  
-      (let* ((result
808  
-              (dtrt-indent--analyze
809  
-               (dtrt-indent--calc-histogram
810  
-                (car language-and-variable))))
811  
-             (best-guess
812  
-              (cdr (assoc :best-guess result)))
813  
-             (rejected
814  
-              (cdr (assoc :rejected result)))
815  
-             (confidence
816  
-              (cdr (assoc :confidence result)))
817  
-             (change-indent-tabs-mode
818  
-              (cdr (assoc :change-indent-tabs-mode result)))
819  
-             (indent-tabs-mode-setting
820  
-              (cdr (assoc :indent-tabs-mode-setting result)))
821  
-             (best-indent-offset
822  
-              (nth 0 best-guess))
823  
-             (indent-offset-variable
824  
-              (nth 1 language-and-variable)))
825  
-        (cond
826  
-         ((and best-guess
827  
-               (not rejected)
828  
-               (not (eq (symbol-value indent-offset-variable)
829  
-                        best-indent-offset)))
830  
-
831  
-          (if dtrt-indent-explicit-offset
832  
-              (message "\
833  
-Indentation offset set with file variable; not adjusted")
834  
-            (when (or (not dtrt-indent-require-confirmation-flag)
835  
-                      (yes-or-no-p
836  
-                       (format "Do you want to adjust %s to %s for buffer %s? "
837  
-                               indent-offset-variable
838  
-                               best-indent-offset
839  
-                               (buffer-name))))
840  
-              (setq dtrt-indent-original-indent
841  
-                    (list indent-offset-variable
842  
-                          (eval indent-offset-variable)
843  
-                          (local-variable-p indent-offset-variable)
844  
-                          indent-tabs-mode
845  
-                          (local-variable-p indent-tabs-mode)))
846  
-              (when (>= dtrt-indent-verbosity 1)
847  
-                (let ((offset-info
848  
-                       (format "%s adjusted to %s%s"
849  
-                               indent-offset-variable
850  
-                               best-indent-offset
851  
-                               (if (>= dtrt-indent-verbosity 2)
852  
-                                   (format " (%.0f%%%% confidence)"
853  
-                                           (* 100 confidence))
854  
-                                 "")))
855  
-                      (tabs-mode-info
856  
-                       (when (and change-indent-tabs-mode
857  
-                                  (not (eql indent-tabs-mode-setting
858  
-                                            indent-tabs-mode)))
859  
-                         (format " and indent-tabs-mode adjusted to %s"
860  
-                                 indent-tabs-mode-setting))))
861  
-                  (message (concat "Note: " offset-info tabs-mode-info))))
862  
-              (set (make-local-variable indent-offset-variable)
863  
-                   best-indent-offset)
864  
-              (when change-indent-tabs-mode
865  
-                (set (make-local-variable 'indent-tabs-mode)
866  
-                     indent-tabs-mode-setting))
867  
-              (setq dtrt-indent-mode-line-info "  [dtrt-indent adjusted]")
868  
-              best-indent-offset)))
869  
-         (t
870  
-          (when (>= dtrt-indent-verbosity 2)
871  
-            (message "Note: %s not adjusted" indent-offset-variable))
872  
-          nil))))))
873  
-
874  
-(defun dtrt-indent-find-file-hook ()
875  
-  "Try adjusting indentation offset when a file is loaded."
876  
-  (when dtrt-indent-mode
877  
-    (dtrt-indent-try-set-offset)))
878  
-
879  
-(defun dtrt-indent-adapt ()
880  
-  "Try adjusting indentation settings for the current buffer."
881  
-  (interactive)
882  
-  (if dtrt-indent-original-indent
883  
-      (message "dtrt-indent already adjusted this buffer")
884  
-    (dtrt-indent-try-set-offset)))
885  
-
886  
-(defun dtrt-indent-undo ()
887  
-  "Undo any change dtrt-indent made to the indentation offset."
888  
-  (interactive)
889  
-  (if (null dtrt-indent-original-indent)
890  
-      (message "No dtrt-indent override to undo in this buffer")
891  
-    (let ((info 
892  
-           (concat
893  
-            (if (nth 2 dtrt-indent-original-indent)
894  
-                (progn
895  
-                  (set (nth 0 dtrt-indent-original-indent)
896  
-                       (nth 1 dtrt-indent-original-indent))
897  
-                  (when (>= dtrt-indent-verbosity 1)
898  
-                    (format "\
899  
-Note: restored original buffer-local value of %d for %s"
900  
-                            (nth 1 dtrt-indent-original-indent)
901  
-                            (nth 0 dtrt-indent-original-indent))))
902  
-              (kill-local-variable (nth 0 dtrt-indent-original-indent))
903  
-              (format "\
904  
-Note: killed buffer-local value for %s, restoring to default %d"
905  
-                      (nth 0 dtrt-indent-original-indent)
906  
-                      (eval (nth 1 dtrt-indent-original-indent))))
907  
-            (if (nth 4 dtrt-indent-original-indent)
908  
-                (progn
909  
-                  (setq indent-tabs-mode
910  
-                        (nth 3 dtrt-indent-original-indent))
911  
-                  (format "\
912  
- and restored original buffer-local value of %s for indent-tabs-mode"
913  
-                          (nth 3 dtrt-indent-original-indent)))
914  
-              (kill-local-variable 'indent-tabs-mode)
915  
-              (format "\
916  
- and killed buffer-local value for indent-tabs-mode, restoring to default %s"
917  
-                      indent-tabs-mode)))))
918  
-      (when (>= dtrt-indent-verbosity 1)
919  
-        (message info))
920  
-      (kill-local-variable 'dtrt-indent-original-indent))))
921  
-
922  
-;;-----------------------------------------------------------------
923  
-;; Installation
924  
-
925  
-(defun dtrt-indent-unload-hook ()
926  
-  "Unload dtrt-indent."
927  
-  (dtrt-indent-mode 0))
928  
-(add-hook 'dtrt-indent-unload-hook 'dtrt-indent-unload-hook)
929  
-
930  
-(defadvice hack-one-local-variable
931  
-  (before dtrt-indent-advise-hack-one-local-variable activate)
932  
-  "Adviced by dtrt-indent.
933  
-
934