mirror of
https://git.savannah.gnu.org/git/emacs.git
synced 2025-01-06 11:55:48 +00:00
45fdb48240
* calculator.el (calculator): Mark unused argument. (calculator-paste, calculator-quit, calculator-integer-p): Use ignore-errors. (calculator-string-to-number, calculator-decimal, calculator-exp) (calculator-op-or-exp): Use string-match-p. * dired-aux.el (dired-compress): Use ignore-errors. (dired-do-chxxx, dired-do-chmod, dired-trample-file-versions) (dired-do-async-shell-command, dired-do-shell-command) (dired-shell-stuff-it, dired-compress-file, dired-insert-subdir) (dired-insert-subdir-validate): Use string-match-p. (dired-map-dired-file-lines, dired-subdir-hidden-p): Use looking-at-p. (dired-add-entry): Use string-match-p, looking-at-p. (dired-insert-subdir-newpos): Remove unused local variable. * dired.el (dired-buffer-more-recently-used-p): Declare. (dired-insert-set-properties, dired-insert-old-subdirs): Use ignore-errors. * filenotify.el (file-notify-callback): Remove unused local variable. * filesets.el (filesets-error): Mark unused argument. (filesets-which-command-p, filesets-filter-dir-names) (filesets-directory-files, filesets-get-external-viewer) (filesets-ingroup-get-data): Use string-match-p. * find-file.el (ff-other-file-name, ff-other-file-name) (ff-find-the-other-file, ff-cc-hh-converter): Remove unused local variables. (ff-get-file-name): Use string-match-p. (ff-all-dirs-under): Use ignore-errors. * follow.el (follow-comint-scroll-to-bottom): Mark unused argument. (follow-select-if-visible): Remove unused local variable. * forms.el (read-file-filter): Move declaration. (forms--make-format, forms--make-parser, forms-insert-record): Quote function with #'. (forms--update): Use string-match-p. Quote function with #'. * help-mode.el (help-dir-local-var-def): Mark unused argument. (help-make-xrefs): Use looking-at-p. (help-xref-on-pp): Use looking-at-p, ignore-errors. * ibuffer.el (ibuffer-ext-visible-p): Declare. (ibuffer-confirm-operation-on): Use string-match-p. * msb.el (msb-item-handler, msb-dired-item-handler): Mark unused arguments. * ses.el (ses-decode-cell-symbol) (ses-kill-override): Remove unused local variable. (ses-create-cell-variable, ses-relocate-formula): Use string-match-p. (ses-load): Use ignore-errors, looking-at-p. (ses-jump-safe): Use ignore-errors. (ses-export-tsv, ses-export-tsf, ses-unsafe): Mark unused arguments. * tabify.el (untabify, tabify): Mark unused arguments. * thingatpt.el (thing-at-point--bounds-of-well-formed-url): Mark unused argument. (bounds-of-thing-at-point, thing-at-point-bounds-of-list-at-point) (thing-at-point-newsgroup-p, form-at-point): Use ignore-errors.
105 lines
4.1 KiB
EmacsLisp
105 lines
4.1 KiB
EmacsLisp
;;; tabify.el --- tab conversion commands for Emacs
|
|
|
|
;; Copyright (C) 1985, 1994, 2001-2013 Free Software Foundation, Inc.
|
|
|
|
;; Maintainer: FSF
|
|
;; Package: emacs
|
|
|
|
;; This file is part of GNU Emacs.
|
|
|
|
;; GNU Emacs is free software: you can redistribute it and/or modify
|
|
;; it under the terms of the GNU General Public License as published by
|
|
;; the Free Software Foundation, either version 3 of the License, or
|
|
;; (at your option) any later version.
|
|
|
|
;; GNU Emacs is distributed in the hope that it will be useful,
|
|
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
;; GNU General Public License for more details.
|
|
|
|
;; You should have received a copy of the GNU General Public License
|
|
;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
;;; Commentary:
|
|
|
|
;; Commands to optimize spaces to tabs or expand tabs to spaces in a region
|
|
;; (`tabify' and `untabify'). The variable tab-width does the obvious.
|
|
|
|
;;; Code:
|
|
|
|
;;;###autoload
|
|
(defun untabify (start end &optional _arg)
|
|
"Convert all tabs in region to multiple spaces, preserving columns.
|
|
If called interactively with prefix ARG, convert for the entire
|
|
buffer.
|
|
|
|
Called non-interactively, the region is specified by arguments
|
|
START and END, rather than by the position of point and mark.
|
|
The variable `tab-width' controls the spacing of tab stops."
|
|
(interactive (if current-prefix-arg
|
|
(list (point-min) (point-max) current-prefix-arg)
|
|
(list (region-beginning) (region-end) nil)))
|
|
(let ((c (current-column)))
|
|
(save-excursion
|
|
(save-restriction
|
|
(narrow-to-region (point-min) end)
|
|
(goto-char start)
|
|
(while (search-forward "\t" nil t) ; faster than re-search
|
|
(forward-char -1)
|
|
(let ((tab-beg (point))
|
|
(indent-tabs-mode nil)
|
|
column)
|
|
(skip-chars-forward "\t")
|
|
(setq column (current-column))
|
|
(delete-region tab-beg (point))
|
|
(indent-to column)))))
|
|
(move-to-column c)))
|
|
|
|
(defvar tabify-regexp " [ \t]+"
|
|
"Regexp matching whitespace that tabify should consider.
|
|
Usually this will be \" [ \\t]+\" to match a space followed by whitespace.
|
|
\"^\\t* [ \\t]+\" is also useful, for tabifying only initial whitespace.")
|
|
|
|
;;;###autoload
|
|
(defun tabify (start end &optional _arg)
|
|
"Convert multiple spaces in region to tabs when possible.
|
|
A group of spaces is partially replaced by tabs
|
|
when this can be done without changing the column they end at.
|
|
If called interactively with prefix ARG, convert for the entire
|
|
buffer.
|
|
|
|
Called non-interactively, the region is specified by arguments
|
|
START and END, rather than by the position of point and mark.
|
|
The variable `tab-width' controls the spacing of tab stops."
|
|
(interactive (if current-prefix-arg
|
|
(list (point-min) (point-max) current-prefix-arg)
|
|
(list (region-beginning) (region-end) nil)))
|
|
(save-excursion
|
|
(save-restriction
|
|
;; Include the beginning of the line in the narrowing
|
|
;; since otherwise it will throw off current-column.
|
|
(goto-char start)
|
|
(beginning-of-line)
|
|
(narrow-to-region (point) end)
|
|
(goto-char start)
|
|
(let ((indent-tabs-mode t))
|
|
(while (re-search-forward tabify-regexp nil t)
|
|
;; The region between (match-beginning 0) and (match-end 0) is just
|
|
;; spacing which we want to adjust to use TABs where possible.
|
|
(let ((end-col (current-column))
|
|
(beg-col (save-excursion (goto-char (match-beginning 0))
|
|
(skip-chars-forward "\t")
|
|
(current-column))))
|
|
(if (= (/ end-col tab-width) (/ beg-col tab-width))
|
|
;; The spacing (after some leading TABs which we wouldn't
|
|
;; want to touch anyway) does not straddle a TAB boundary,
|
|
;; so it neither contains a TAB, nor will we be able to use
|
|
;; a TAB here anyway: there's nothing to do.
|
|
nil
|
|
(delete-region (match-beginning 0) (point))
|
|
(indent-to end-col))))))))
|
|
|
|
(provide 'tabify)
|
|
|
|
;;; tabify.el ends here
|