Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 495 lines (461 sloc) 20.053 kb
8fd38d5 first commit
Le Wang authored
1 ;;; auto-indent-lite.el --- auto indent when yank/yank-pop/kill-line
2 ;;
3 ;; Filename: auto-indent-lite-mode.el
4 ;; Description: Auto Indent text on Yank/Paste
5 ;; Author: Matthew L. Fidler & Others
6 ;; Maintainer: Le Wang
7 ;; Created: Sat Nov 6 11:02:07 2010 (-0500)
8 ;; Version: 0.3
6572181 add coffee-mode to exclude list
Le Wang authored
9 ;; Last-Updated: Tue Apr 3 14:22:08 2012 (+0800)
8fd38d5 first commit
Le Wang authored
10 ;;
11 ;; 21:13:09 2011 (+0800)
12 ;; By: Le Wang
6572181 add coffee-mode to exclude list
Le Wang authored
13 ;; Update #: 515
5761e47 update URL in header
Le Wang authored
14 ;;
15 ;; URL: https://github.com/lewang/le_emacs_libs/blob/master/auto-indent-lite.el
16 ;;
17 ;;
18 ;; Keywords: Auto Indentation Compatibility: Tested with Emacs 23.2.1
8fd38d5 first commit
Le Wang authored
19 ;;
20 ;; Features that might be required by this library:
21 ;;
22 ;; None
23 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
24
25 ;; This is auto-indent-mode without the minor-mode, and any hook setup.
26 ;;
27 ;; Only smart yank/yank-pop, and kill-line is left.
28 ;;
29 ;; This is completely *INCOMPATIBLE* with auto-indent-mode.el, if you need to
51fc91a add threshold to auto-indent-lite
Le Wang authored
30 ;; ensure correct indention at all times, I strongly recommend
8fd38d5 first commit
Le Wang authored
31 ;; auto-indent-mode.el.
32 ;;
33 ;; Installation:
34 ;;
35 ;; (require 'auto-indent-light) (setq auto-indent-mode t)
36 ;;
51fc91a add threshold to auto-indent-lite
Le Wang authored
37 ;; Customization:
8fd38d5 first commit
Le Wang authored
38 ;;
39 ;; M-x customize-group, "auto-indent"
40
41 ;;; Commentary (from auto-indent-mode.el):
42
43 ;; Provides auto-indentation minor mode. This allows the following:
44 ;;
45 ;; (1) Return automatically indents the code appropriately (if enabled)
46 ;;
47 ;; (2) Pasting/Yanking indents the appropriately
48 ;;
49 ;; (3) Killing line will take off unneeded spaces (if enabled)
50 ;;
51 ;; (4) On visit file, indent appropriately, but DONT SAVE. (Pretend like
52 ;; nothing happened, if enabled)
53 ;;
54 ;; (5) On save, optionally unttabify, remove trailing white-spaces, and
55 ;; definitely indent the file (if enabled).
56 ;;
57 ;; (6) TextMate behavior of keys if desired (see below)
58 ;;
59 ;; All of these options can be customized. (customize auto-indent)
60 ;;
61 ;; To use put this in your load path and then put the following in your emacs
62 ;; file:
63 ;;
64 ;; (setq auto-indent-on-visit-file t) ;; If you want auto-indent on for files
65 ;; (require 'auto-indent-mode)
66 ;;
67 ;; If you (almost) always want this on, add the following to ~/.emacs:
68 ;;
69 ;; (auto-indent-global-mode)
70 ;;
71 ;; Excluded modes are defined in `auto-indent-disabled-modes-list'
72 ;;
73 ;; If you only want this on for a single mode, you would add the following to
74 ;; ~/.emacs
75 ;;
76 ;; (add-hook 'emacs-lisp-mode-hook 'auto-indent-minor-mode)
77 ;;
78 ;; You could always turn on the minor mode with the command
79 ;; `auto-indent-minor-mode'
80 ;;
81 ;; If you would like TextMate behavior of Meta-RETURN going to the end of the
82 ;; line and then inserting a newline, as well as Meta-shift return going to
83 ;; the end of the line, inserting a semi-colon then inserting a newline, use
84 ;; the following:
85 ;;
86 ;;
87 ;; (setq auto-indent-key-for-end-of-line-then-newline "<M-return>") (setq
88 ;; auto-indent-key-for-end-of-line-insert-char-then-newline "<M-S-return>")
89 ;; (require 'auto-indent-mode) (auto-indent-global-mode)
90 ;;
91 ;; This may or may not work on your system. Many times emacs cannot
92 ;; distinguish between M-RET and M-S-RET, so if you don't mind a slight
93 ;; redefinition use:
94 ;;
95 ;; (setq auto-indent-key-for-end-of-line-then-newline "<M-return>") (setq
96 ;; auto-indent-key-for-end-of-line-insert-char-then-newline "<C-M-return>")
97 ;; (require 'auto-indent-mode) (auto-indent-global-mode)
98 ;;
99 ;;
100 ;; If you want to insert something other than a semi-colon (like a colon) in
101 ;; a specific mode, say colon-mode, do the following:
102 ;;
103 ;; (add-hook 'colon-mode-hook (lambda () (setq auto-indent-eol-char ":")))
104 ;;
105 ;;
106 ;; If you wish to use this with autopairs and yasnippet, please load this
107 ;; library first.
108 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
109 ;;
110 ;;; Change Log:
111 ;; 31-Jan-2011 Matthew L. Fidler
112 ;; Last-Updated: Mon Jan 31 22:05:59 2011 (-0600) #440 (Matthew L. Fidler)
113 ;; Removed indirect reference to `shrink-whitespaces'. Thanks Le Wang
114 ;; 31-Jan-2011 Matthew L. Fidler
115 ;; Last-Updated: Mon Jan 31 21:27:39 2011 (-0600) #435 (Matthew L. Fidler)
116 ;; Added explicit requirement for functions
117 ;; 18-Jan-2011 Matthew L. Fidler
118 ;; Last-Updated: Tue Jan 18 10:23:43 2011 (-0600) #428 (Matthew L. Fidler)
119 ;; Added support to turn on `org-indent-mode' when inside an org-file.
120 ;; 12-Jan-2011 Matthew L. Fidler
121 ;; Last-Updated: Wed Jan 12 16:27:21 2011 (-0600) #420 (Matthew L. Fidler)
122 ;; Added fix for ortbl-minor-mode. Now it will work when orgtbl-minor mode
123 ;; is enabled.
124 ;; 09-Dec-2010 Matthew L. Fidler
125 ;; Last-Updated: Thu Dec 9 09:17:45 2010 (-0600) #414 (Matthew L. Fidler)
126 ;; Bugfix. Now instead of indenting the region pasted, indent the
127 ;; region-pasted + beginning of line at region begin and end of line at
128 ;; region end.
129 ;; 02-Dec-2010 Matthew L. Fidler
130 ;; Last-Updated: Thu Dec 2 13:02:02 2010 (-0600) #411 (Matthew L. Fidler)
131 ;; Made ignoring of modes with indent-relative and indent-relative-maybe
132 ;; apply to indenting returns as well.
133 ;; 02-Dec-2010 Matthew L. Fidler
134 ;; Last-Updated: Thu Dec 2 11:38:37 2010 (-0600) #402 (Matthew L. Fidler)
135 ;; Removed auto-indent on paste/yank for modes with indent-relative and
136 ;; indent-relative-maybe. This has annoyed me forever.
137 ;; 02-Dec-2010 Matthew L. Fidler
138 ;; Last-Updated: Thu Dec 2 10:40:05 2010 (-0600) #397 (Matthew L. Fidler)
139 ;; Added an advice to delete-char. When deleting a new-line character,
140 ;; shrink white-spaces afterward.
141 ;; 02-Dec-2010 Matthew L. Fidler
142 ;; Last-Updated: Thu Dec 2 08:59:49 2010 (-0600) #386 (Matthew L. Fidler)
143 ;; Speed enhancement by checking for yasnippets only on indentation.
144 ;; 29-Nov-2010 Matthew L. Fidler
145 ;; Last-Updated: Mon Nov 29 13:19:38 2010 (-0600) #377 (Matthew L. Fidler)
146 ;; Bug fix to allow authotkey files to save.
147 ;; 29-Nov-2010 Matthew L. Fidler
148 ;; Last-Updated: Mon Nov 29 12:10:09 2010 (-0600) #367 (Matthew L. Fidler)
149 ;; Change auto-indent-on-save to be disabled by default.
150 ;; 22-Nov-2010 Matthew L. Fidler
151 ;; Last-Updated: Mon Nov 22 14:36:10 2010 (-0600) #365 (Matthew L. Fidler)
152 ;; Yasnippet bug-fix.
153 ;; 22-Nov-2010 Matthew L. Fidler
154 ;; Last-Updated: Mon Nov 22 12:00:07 2010 (-0600) #363 (Matthew L. Fidler)
155 ;; auto-indent bug fix for save on save buffer hooks.
156 ;; 16-Nov-2010 Matthew L. Fidler
157 ;; Last-Updated: Tue Nov 16 13:16:05 2010 (-0600) #361 (Matthew L. Fidler)
158 ;; Added conf-windows-mode to ignored modes.
159 ;; 15-Nov-2010 Matthew L. Fidler
160 ;; Last-Updated: Mon Nov 15 17:23:03 2010 (-0600) #354 (Matthew L. Fidler)
161 ;; Bugfix for deletion of whitespace
162 ;; 15-Nov-2010 Matthew L. Fidler
163 ;; Last-Updated: Mon Nov 15 14:27:50 2010 (-0600) #351 (Matthew L. Fidler)
164 ;; Bugfix for post-command-hook.
165 ;; 15-Nov-2010 Matthew L. Fidler
166 ;; Last-Updated: Mon Nov 15 08:53:03 2010 (-0600) #338 (Matthew L. Fidler)
167 ;; Added diff-mode to excluded modes for auto-indentaion.
168 ;; 15-Nov-2010 Matthew L. Fidler
169 ;; Last-Updated: Mon Nov 15 00:22:30 2010 (-0600) #336 (Matthew L. Fidler)
170 ;; Added fundamental mode to excluded modes for auto-indentation.
171 ;; 13-Nov-2010 Matthew L. Fidler
172 ;; Last-Updated: Sat Nov 13 20:03:10 2010 (-0600) #334 (Matthew L. Fidler)
173 ;; Bug fix try #3
174 ;; 13-Nov-2010 Matthew L. Fidler
175 ;; Last-Updated: Sat Nov 13 19:55:29 2010 (-0600) #329 (Matthew L. Fidler)
176 ;; Anothe bug-fix for yasnippet.
177 ;; 13-Nov-2010 Matthew L. Fidler
178 ;; Last-Updated: Sat Nov 13 19:49:47 2010 (-0600) #325 (Matthew L. Fidler)
179 ;;
180 ;; Bug fix for auto-indent-mode. Now it checks to make sure that
181 ;; `last-command-event' is non-nil.
182 ;;
183 ;; 11-Nov-2010 Matthew L. Fidler
184 ;; Last-Updated: Thu Nov 11 13:56:15 2010 (-0600) #308 (Matthew L. Fidler)
185 ;; Put back processes in. Made the return key handled by pre and
186 ;; post-command-hooks.
187 ;; 11-Nov-2010 Matthew L. Fidler
188 ;; Last-Updated: Thu Nov 11 11:28:42 2010 (-0600) #257 (Matthew L. Fidler)
189 ;; Took out processes such as *R* or *eshell*
190 ;; 09-Nov-2010 Matthew L. Fidler
191 ;; Last-Updated: Tue Nov 9 22:03:34 2010 (-0600) #255 (Matthew L. Fidler)
192 ;;
193 ;; Bug fix when interacting with the SVN version of yasnippet. It will not
194 ;; perform the line indentation when Yasnippet is running.
195 ;;
196 ;; 09-Nov-2010 Matthew L. Fidler
197 ;; Last-Updated: Tue Nov 9 13:47:18 2010 (-0600) #253 (Matthew L. Fidler)
198 ;; Made sure that the auto-paste indentation doesn't work in minibuffer.
199 ;; 09-Nov-2010 Matthew L. Fidler
200 ;; Last-Updated: Tue Nov 9 11:51:07 2010 (-0600) #246 (Matthew L. Fidler)
201 ;; When `auto-indent-pre-command-hook' is inactivated by some means, add it
202 ;; back.
203 ;; 09-Nov-2010
204 ;; Last-Updated: Tue Nov 9 11:13:09 2010 (-0600) #238 (Matthew L. Fidler)
205 ;; Added snippet-mode to excluded modes. Also turned off the kill-line by
206 ;; default.
207 ;; 07-Nov-2010 Matthew L. Fidler
208 ;; Last-Updated: Sun Nov 7 18:24:05 2010 (-0600) #233 (Matthew L. Fidler)
209 ;; Added the possibility of TextMate type returns.
210 ;; 07-Nov-2010 Matthew L. Fidler
211 ;; Last-Updated: Sun Nov 7 00:54:07 2010 (-0500) #180 (Matthew L. Fidler)
212 ;; Bug fix where backspace on indented region stopped working.Added
213 ;; TextMate
214 ;; 07-Nov-2010 Matthew L. Fidler
215 ;; Last-Updated: Sun Nov 7 00:30:54 2010 (-0500) #167 (Matthew L. Fidler)
216 ;; Another small bug fix.
217 ;; 07-Nov-2010 Matthew L. Fidler
218 ;; Last-Updated: Sun Nov 7 00:21:38 2010 (-0500) #154 (Matthew L. Fidler)
219 ;;
220 ;; Added bugfix and also allow movement on blank lines to be automatically
221 ;; indented to the correct position.
222 ;;
223 ;; 06-Nov-2010 Matthew L. Fidler
224 ;; Last-Updated: Sat Nov 6 17:39:59 2010 (-0500) #113 (Matthew L. Fidler)
225 ;; Initial release.
226 ;;
227 ;;
228 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
229 ;;
230 ;; This program is free software; you can redistribute it and/or
231 ;; modify it under the terms of the GNU General Public License as
232 ;; published by the Free Software Foundation; either version 3, or
233 ;; (at your option) any later version.
234 ;;
235 ;; This program is distributed in the hope that it will be useful, but WITHOUT
236 ;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
237 ;; FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
238 ;; more details.
239 ;;
240 ;; You should have received a copy of the GNU General Public License along
241 ;; with this program; see the file COPYING. If not, write to the Free
242 ;; Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
243 ;; 02110-1301, USA.
244 ;;
245 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
246 ;;
247 ;;; Code:
248
249 (eval-when-compile
250 (require 'cl))
251
252 (defgroup auto-indent nil
253 "* Auto Indent Mode Customizations"
254 :group 'editing)
255
256 (defcustom auto-indent-mode nil
257 "when t, adviced functions are active, else not active."
258 :type 'boolean
259 :group 'auto-indent)
260
51fc91a add threshold to auto-indent-lite
Le Wang authored
261 (defcustom auto-indent-threshhold 1500
262 "regions larger than this value will not be indented"
263 :type 'integer
264 :group 'auto-indent)
265
8fd38d5 first commit
Le Wang authored
266 (defcustom auto-indent-mode-untabify-on-yank-or-paste 't
267 "* Untabify pasted or yanked region."
268 :type 'boolean
269 :group 'auto-indent)
270
271 (defcustom auto-indent-delete-line-char-remove-extra-spaces t
272 "* When deleting a return, delete any extra spaces between the newly joined lines"
273 :type 'boolean
274 :group 'auto-indent)
275
276 (defcustom auto-indent-kill-line-remove-extra-spaces t
277 "* When killing lines, remove extra spaces before killing the line."
278 :type 'boolean
279 :group 'auto-indent)
280
452309b add 'subsequent-whole-line kill-line-at-eol option
Le Wang authored
281 (defcustom auto-indent-kill-line-at-eol 'subsequent-whole-line
8fd38d5 first commit
Le Wang authored
282 "* When killing lines, if at the end of a line,
283
284 nil - join next line to the current line. Deletes whitespace at
d6a1716 change default kill-line-at-eol to 'whole-line
Le Wang authored
285 join. [this essentially duplicated delete-char]
8fd38d5 first commit
Le Wang authored
286 See also `auto-indent-kill-line-remove-extra-spaces'
287 whole-lines - kill next lines
288 blanks - kill all empty lines after the current line, and then
289 any lines specified.
290
291 You should also set `kill-whole-line' to do what you want.
292
293 "
294 :type '(choice (const :tag "default" nil)
295 (const :tag "next whole line" whole-line)
452309b add 'subsequent-whole-line kill-line-at-eol option
Le Wang authored
296 (const :tag "merge lines on first call, subsequent kill whole lines" subsequent-whole-line)
8fd38d5 first commit
Le Wang authored
297 (const :tag "next whole line after any blank lines" blanks))
298 :group 'auto-indent)
299
300 (defcustom auto-indent-use-text-boundaries nil
301 "* When killing lines, if point is before any text, act as if
302 point is at BOL. And if point is after text, act as if point
303 is at EOL"
304 :type 'boolean
305 :group 'auto-indent)
306
f7c116e add yaml to disabled modes
Le Wang authored
307 (defcustom auto-indent-disabled-modes-list
308 '(eshell-mode
309 wl-summary-mode
310 compilation-mode
311 org-mode
312 text-mode
313 dired-mode
314 snippet-mode
315 fundamental-mode
316 diff-mode
317 texinfo-mode
c51a234 move scf-mode into submodule
Le Wang authored
318 yaml-mode
393aab9 add mmm-mode to default exclude list
Le Wang authored
319 log-edit-mode
51fc91a add threshold to auto-indent-lite
Le Wang authored
320 sql-mode
6572181 add coffee-mode to exclude list
Le Wang authored
321 coffee-mode
393aab9 add mmm-mode to default exclude list
Le Wang authored
322 (lambda ()
51fc91a add threshold to auto-indent-lite
Le Wang authored
323 (not (derived-mode-p 'conf-mode 'markdown-mode)))
8be53a6 exclude children of conf-mode
Le Wang authored
324 (lambda ()
393aab9 add mmm-mode to default exclude list
Le Wang authored
325 (not (and (boundp 'mmm-mode)
326 mmm-mode))))
327 "* List of major-modes which should not auto-indent.
328
329 Predicates can also be used in this list. If a predicate returns
51fc91a add threshold to auto-indent-lite
Le Wang authored
330 nil, then auto-indent will not happen."
8fd38d5 first commit
Le Wang authored
331 :type '(repeat (sexp :tag "Major mode"))
332 :group 'auto-indent)
333
74f3921 really fix major-mode check
Le Wang authored
334 (defadvice yank (after auto-indent-mode-advice activate)
393aab9 add mmm-mode to default exclude list
Le Wang authored
335 (when (and (auto-indent-lite-p)
74f3921 really fix major-mode check
Le Wang authored
336 (or (called-interactively-p 'any)
337 (memq this-command (list (key-binding [(control y)]) 'yank)))
393aab9 add mmm-mode to default exclude list
Le Wang authored
338 (not current-prefix-arg))
74f3921 really fix major-mode check
Le Wang authored
339 (let ((mark-even-if-inactive transient-mark-mode))
a2fd7ae modify space triming at yank point to delete beginning spaces of yanked ...
Le Wang authored
340 (when auto-indent-use-text-boundaries
93d5fd2 move point correctly after yank
Le Wang authored
341 (let ((orig-m (point-marker)))
a2fd7ae modify space triming at yank point to delete beginning spaces of yanked ...
Le Wang authored
342 (goto-char (mark))
93d5fd2 move point correctly after yank
Le Wang authored
343 (backward-delete-char (skip-chars-forward " \t"))
344 (goto-char orig-m)))
51fc91a add threshold to auto-indent-lite
Le Wang authored
345 (if (< (- (region-end) (region-beginning)) auto-indent-threshhold)
346 (indent-region (region-beginning) (region-end))
347 (message "refusing to indent yanked region is larger than %s characters" auto-indent-threshhold))
957bc9f indent after yank and yank-pop
Le Wang authored
348 (indent-according-to-mode)
74f3921 really fix major-mode check
Le Wang authored
349 (if auto-indent-mode-untabify-on-yank-or-paste
350 (untabify (region-beginning) (region-end))))))
8fd38d5 first commit
Le Wang authored
351
74f3921 really fix major-mode check
Le Wang authored
352 (defadvice yank-pop (after auto-indent-mode-advice activate)
393aab9 add mmm-mode to default exclude list
Le Wang authored
353 (when (and (auto-indent-lite-p)
74f3921 really fix major-mode check
Le Wang authored
354 (or (called-interactively-p 'any)
355 (memq this-command (list (key-binding [(meta y)]) 'yank)))
393aab9 add mmm-mode to default exclude list
Le Wang authored
356 (not current-prefix-arg))
74f3921 really fix major-mode check
Le Wang authored
357 (let ((mark-even-if-inactive transient-mark-mode))
a2fd7ae modify space triming at yank point to delete beginning spaces of yanked ...
Le Wang authored
358 (when auto-indent-use-text-boundaries
93d5fd2 move point correctly after yank
Le Wang authored
359 (let ((orig-m (point-marker)))
360 (goto-char (mark))
361 (backward-delete-char (skip-chars-forward " \t"))
362 (goto-char orig-m)))
51fc91a add threshold to auto-indent-lite
Le Wang authored
363 (if (< (- (region-end) (region-beginning)) auto-indent-threshhold)
364 (indent-region (region-beginning) (region-end))
365 (message "pasted region is bigger than %s characters" auto-indent-threshhold))
957bc9f indent after yank and yank-pop
Le Wang authored
366 (indent-according-to-mode)
74f3921 really fix major-mode check
Le Wang authored
367 (if auto-indent-mode-untabify-on-yank-or-paste
368 (untabify (region-beginning) (region-end))))))
8fd38d5 first commit
Le Wang authored
369
370 (defadvice delete-char (around auto-indent-mode activate)
74f3921 really fix major-mode check
Le Wang authored
371 "If at the end of the line, take out whitespace after deleting character
372
373 This advice only works when you press the key mapped to
374 delete-char. The behaviour of delete-char shouldn't be changed
375 in non-interactive calls.
376 "
377 (if (or (called-interactively-p 'any)
378 (eq (key-binding [delete]) this-command))
8fd38d5 first commit
Le Wang authored
379 (let ((del-eol (eolp)))
380 ad-do-it
381 (when (and del-eol
382 auto-indent-mode
383 (not (minibufferp))
384 auto-indent-delete-line-char-remove-extra-spaces)
ad5fe90 use fixup-space instead of own function
Le Wang authored
385 (fixup-whitespace)
8fd38d5 first commit
Le Wang authored
386 (when (and (eolp) (looking-back "[ \t]+" nil t))
387 (replace-match ""))))
388 ad-do-it))
389
390 (defadvice kill-line (around auto-indent-mode activate)
391 "Obey `auto-indent-use-text-boundaries'.
392
26015e7 added C-u kills line backwards functionality
Le Wang authored
393 Kill region if region is active
394
395 Kill backwards if UNIVERSAL ARG C-u is passed.
396
8fd38d5 first commit
Le Wang authored
397 If at end of line, obey `auto-indent-kill-line-at-eol'
26015e7 added C-u kills line backwards functionality
Le Wang authored
398
5f602a1 implement consecutive kill appends to last kill
Le Wang authored
399 Consecutive kill-lines cause lines to be appended to last kill.
400
8fd38d5 first commit
Le Wang authored
401 "
26015e7 added C-u kills line backwards functionality
Le Wang authored
402 (if (and auto-indent-mode
403 (not (minibufferp))
404 (or (called-interactively-p 'any)
405 (memq this-command (list (key-binding [(control k)])))))
5e963aa fixed bug in append subsequent kills to last kill
Le Wang authored
406 (let ((last-command last-command)
5f602a1 implement consecutive kill appends to last kill
Le Wang authored
407 (ad-get-arg-0-int (prefix-numeric-value (ad-get-arg 0))))
5e963aa fixed bug in append subsequent kills to last kill
Le Wang authored
408 (when (memq this-command (list last-command))
5f602a1 implement consecutive kill appends to last kill
Le Wang authored
409 ;; this may change this-command to 'kill-region
410 (append-next-kill))
411
783125b remove auto-indent-kill-line-kill-region-when-active in deference to del...
Le Wang authored
412 (cond ((and delete-selection-mode
26015e7 added C-u kills line backwards functionality
Le Wang authored
413 (use-region-p))
414 (kill-region (region-beginning) (region-end)))
5f602a1 implement consecutive kill appends to last kill
Le Wang authored
415 ((and (ad-get-arg 0) (listp (ad-get-arg 0)))
26015e7 added C-u kills line backwards functionality
Le Wang authored
416 (if (auto-indent-bolp)
417 (ad-set-arg 0 -1)
418 (ad-set-arg 0 0))
419 ad-do-it)
420 ((auto-indent-bolp)
421 (move-beginning-of-line 1)
422 ad-do-it)
423 ((auto-indent-eolp)
424 (cond ((eq auto-indent-kill-line-at-eol nil)
5f602a1 implement consecutive kill appends to last kill
Le Wang authored
425 (if (= ad-get-arg-0-int 1)
5e963aa fixed bug in append subsequent kills to last kill
Le Wang authored
426 (let ((old-point (point-marker))
427 kill-char-count)
428 (kill-region (point)
429 (progn
430 (goto-char (point-at-bol 2))
431 (skip-chars-forward " \t")
432 (setq kill-char-count (- (point) old-point))
433 (point)))
434 (goto-char old-point)
435 (when (> kill-char-count 1)
436 (insert " ")
437 (backward-char 1)))
26015e7 added C-u kills line backwards functionality
Le Wang authored
438 ad-do-it))
439 ((eq auto-indent-kill-line-at-eol 'subsequent-whole-line)
440 (let (auto-indent-kill-line-at-eol)
5e963aa fixed bug in append subsequent kills to last kill
Le Wang authored
441 (if (memq last-command (list 'kill-region this-command))
26015e7 added C-u kills line backwards functionality
Le Wang authored
442 (progn
443 (setq auto-indent-kill-line-at-eol 'whole-line)
5f602a1 implement consecutive kill appends to last kill
Le Wang authored
444 (kill-line (ad-get-arg 0)))
26015e7 added C-u kills line backwards functionality
Le Wang authored
445 (setq auto-indent-kill-line-at-eol nil)
5f602a1 implement consecutive kill appends to last kill
Le Wang authored
446 (kill-line (ad-get-arg 0)))))
26015e7 added C-u kills line backwards functionality
Le Wang authored
447 ((memq auto-indent-kill-line-at-eol '(whole-line blanks))
5f602a1 implement consecutive kill appends to last kill
Le Wang authored
448 (if (> (prefix-numeric-value (ad-get-arg 0)) 0)
449 (progn
26015e7 added C-u kills line backwards functionality
Le Wang authored
450 (delete-region (point) (point-at-eol))
451 (unless (eobp)
5f602a1 implement consecutive kill appends to last kill
Le Wang authored
452 (kill-region (point)
453 (if (eq auto-indent-kill-line-at-eol 'blanks)
454 (+ (point)
455 (skip-chars-forward " \t\n")
456 (skip-chars-backward " \t")
457 ;;
458 -1)
459 (point-at-eol (1+ ad-get-arg-0-int))))))))
26015e7 added C-u kills line backwards functionality
Le Wang authored
460 (t
461 (error "invalid auto-indent-kill-line-at-eol setting %s"
462 auto-indent-kill-line-at-eol))))
463 (t
464 ad-do-it))
393aab9 add mmm-mode to default exclude list
Le Wang authored
465 (when (auto-indent-lite-p)
5f602a1 implement consecutive kill appends to last kill
Le Wang authored
466 (indent-according-to-mode)))
467 ad-do-it))
8fd38d5 first commit
Le Wang authored
468
469 (defun auto-indent-eolp ()
470 "returns t if point is at eol respecting `auto-indent-use-text-boundaries'"
471 (if auto-indent-use-text-boundaries
472 (looking-at-p "[ \t]*$")
473 (eolp)))
474
475 (defun auto-indent-bolp ()
476 "returns t if point is at bol respecting `auto-indent-use-text-boundaries'"
477 (if auto-indent-use-text-boundaries
478 (looking-back "^[ \t]*")
479 (bolp)))
480
393aab9 add mmm-mode to default exclude list
Le Wang authored
481
482 (defun auto-indent-lite-p ()
483 (and auto-indent-mode
484 (not (dolist (x auto-indent-disabled-modes-list)
485 (if (symbolp x)
486 (when (eq major-mode x)
487 (return t))
488 (unless (funcall x)
489 (return t)))))
490 (not (minibufferp))))
491
8fd38d5 first commit
Le Wang authored
492 (provide 'auto-indent-lite)
493 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
f7c116e add yaml to disabled modes
Le Wang authored
494 ;;; auto-indent-lite.el ends here
Something went wrong with that request. Please try again.