;;; which-field.el --- Report current field number
;; Copyright (C) 2012 Andreas Roehler
;; Author: Andreas Roehler
;; Keywords: convenience
;; This program 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.
;; This program 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 this program. If not, see .
;;; Commentary:
;; See csv-mode.el and csv-nav.el for a complete environment
;;; Code:
(defcustom separator-char ";"
"Customize field separator"
:type 'string
:group 'convenience)
(make-variable-buffer-local 'separator-char)
(defalias 'which-field 'match-separators)
(defun match-separators (&optional separator)
"Reports number of field-at-point separated by `separator-char'.
With \\[universal-argument] specify any other char for current buffer.
Returns field-number. `separator-char' is customizable. "
(interactive "P")
(let ((sepa (cond ((eq 4 (prefix-numeric-value separator))
(read-from-minibuffer "Seperator: "))
(separator separator)
(t (default-value 'separator-char))))
erg)
(setq separator-char sepa)
(setq erg (1+ (count-matches sepa (line-beginning-position) (point))))
(when (interactive-p) (message "%s" (message "%s" erg)))
erg))
(provide 'which-field)
;;; which-field.el ends here