home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Fresh Fish 4
/
FreshFish_May-June1994.bin
/
bbs
/
gnu
/
emacs-18.59-bin.lha
/
lib
/
emacs
/
18.59
/
lisp
/
simple.el
< prev
next >
Wrap
Lisp/Scheme
|
1992-11-21
|
51KB
|
1,465 lines
;; Basic editing commands for Emacs
;; Copyright (C) 1985, 1986, 1987, 1992 Free Software Foundation, Inc.
;; 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 1, 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; see the file COPYING. If not, write to
;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
(defun open-line (arg)
"Insert a newline and leave point before it.
With arg, inserts that many newlines."
(interactive "*p")
(let ((flag (and (bolp) (not (bobp)))))
(if flag (forward-char -1))
(while (> arg 0)
(insert ?\n)
(goto-char (1- (point)))
(setq arg (1- arg)))
(if flag (forward-char 1))))
(defun split-line ()
"Split current line, moving portion beyond point vertically down."
(interactive "*")
(skip-chars-forward " \t")
(let ((col (current-column))
(pos (point)))
(insert ?\n)
(indent-to col 0)
(goto-char pos)))
(defun quoted-insert (arg)
"Read next input character and insert it.
Useful for inserting control characters.
You may also type up to 3 octal digits, to insert a character with that code"
(interactive "*p")
(let ((char (read-quoted-char)))
(while (> arg 0)
(insert char)
(setq arg (1- arg)))))
(defun delete-indentation (&optional arg)
"Join this line to previous and fix up whitespace at join.
With argument, join this line to following line."
(interactive "*P")
(beginning-of-line)
(if arg (forward-line 1))
(if (eq (preceding-char) ?\n)
(progn
(delete-region (point) (1- (point)))
(fixup-whitespace))))
(defun fixup-whitespace ()
"Fixup white space between objects around point.
Leave one space or none, according to the context."
(interactive "*")
(save-excursion
(delete-horizontal-space)
(if (or (looking-at "^\\|\\s)\\|$")
(save-excursion (forward-char -1)
(looking-at "\\s(\\|\\s'")))
nil
(insert ?\ ))))
(defun delete-horizontal-space ()
"Delete all spaces and tabs around point."
(interactive "*")
(skip-chars-backward " \t")
(delete-region (point) (progn (skip-chars-forward " \t") (point))))
(defun just-one-space ()
"Delete all spaces and tabs around point, leaving one space."
(interactive "*")
(skip-chars-backward " \t")
(if (= (following-char) ? )
(forward-char 1)
(insert ? ))
(delete-region (point) (progn (skip-chars-forward " \t") (point))))
(defun delete-blank-lines ()
"On blank line, delete all surrounding blank lines, leaving just one.
On isolated blank line, delete that one.
On nonblank line, delete all blank lines that follow it."
(interactive "*")
(let (thisblank singleblank)
(save-excursion
(beginning-of-line)
(setq thisblank (looking-at "[ \t]*$"))
(setq singleblank
(and thisblank
(not (looking-at "[ \t]*\n[ \t]*$"))
(or (bobp)
(progn (forward-line -1)
(not (looking-at "[ \t]*$")))))))
(if thisblank
(progn
(beginning-of-line)
(if singleblank (forward-line 1))
(delete-region (point)
(if (re-search-backward "[^ \t\n]" nil t)
(progn (forward-line 1) (point))
(point-min)))))
(if (not (and thisblank singleblank))
(save-excursion
(end-of-line)
(forward-line 1)
(delete-region (point)
(if (re-search-forward "[^ \t\n]" nil t)
(progn (beginning-of-line) (point))
(point-max)))))))
(defun back-to-indentation ()
"Move point to the first non-whitespace character on this line."
(interactive)
(beginning-of-line 1)
(skip-chars-forward " \t"))
(defun newline-and-indent ()
"Insert a newline, then indent according to major mode.
Indentation is done using the current indent-line-function.
In programming language modes, this is the same as TAB.
In some text modes, where TAB inserts a tab, this indents to the
specified left-margin column."
(interactive "*")
(delete-region (point) (progn (skip-chars-backward " \t") (point)))
(newline)
(indent-according-to-mode))
(defun reindent-then-newline-and-indent ()
"Reindent current line, insert newline, then indent the new line.
Indentation of both lines is done according to the current major mode,
which means that the current value of indent-line-function is called.
In programming language modes, this is the same as TAB.
In some text modes, where TAB inserts a tab, this indents to the
specified left-margin column."
(interactive "*")
(save-excursion
(delete-region (point) (progn (skip-chars-backward " \t") (point)))
(indent-according-to-mode))
(newline)
(indent-according-to-mode))
(defun kill-forward-chars (arg)
(if (listp arg) (setq arg (car arg)))
(if (eq arg '-) (setq arg -1))
(kill-region (point) (+ (point) arg)))
(defun kill-backward-chars (arg)
(if (listp arg) (setq arg (car arg)))
(if (eq arg '-) (setq arg -1))
(kill-region (point) (- (point) arg)))
(defun backward-delete-char-untabify (arg &optional killp)
"Delete characters backward, changing tabs into spaces.
Delete ARG chars, and kill (save in kill ring) if KILLP is non-nil.
Interactively, ARG is the prefix arg (default 1)
and KILLP is t if prefix arg is was specified."
(interactive "*p\nP")
(let ((count arg))
(save-excursion
(while (and (> count 0) (not (bobp)))
(if (= (preceding-char) ?\t)
(let ((col (current-column)))
(forward-char -1)
(setq col (- col (current-column)))
(insert-char ?\ col)
(delete-char 1)))
(forward-char -1)
(setq count (1- count)))))
(delete-backward-char arg killp))
(defun zap-to-char (arg char)
"Kill up to (but not including) ARG'th occurrence of CHAR.
Goes backward if ARG is negative; goes to end of buffer if CHAR not found."
(interactive "*p\ncZap to char: ")
(kill-region (point) (if (search-forward (char-to-string char) nil t arg)
(progn (goto-char (if (> arg 0) (1- (point)) (1+ (point))))
(point))
(if (> arg 0) (point-max) (point-min)))))
(defun beginning-of-buffer (&optional arg)
"Move point to the beginning of the buffer; leave mark at previous position.
With arg N, put point N/10 of the way from the true beginning.
Don't use this in Lisp programs!
\(goto-char (point-min)) is faster and does not set the mark."
(interactive "P")
(push-mark)
(goto-char (if arg
(if (> (buffer-size) 10000)
;; Avoid overflow for large buffer sizes!
(* (prefix-numeric-value arg)
(/ (buffer-size) 10))
(/ (+ 10 (* (buffer-size) (prefix-numeric-value arg))) 10))
(point-min)))
(if arg (forward-line 1)))
(defun end-of-buffer (&optional arg)
"Move point to the end of the buffer; leave mark at previous position.
With arg N, put point N/10 of the way from the true end.
Don't use this in Lisp programs!
\(goto-char (point-max)) is faster and does not set the mark."
(interactive "P")
(push-mark)
(goto-char (if arg
(- (1+ (buffer-size))
(if (> (buffer-size) 10000)
;; Avoid overflow for large buffer sizes!
(* (prefix-numeric-value arg)
(/ (buffer-size) 10))
(/ (* (buffer-size) (prefix-numeric-value arg)) 10)))
(point-max)))
(if arg (forward-line 1)))
(defun mark-whole-buffer ()
"Put point at beginning and mark at end of buffer."
(interactive)
(push-mark (point))
(push-mark (point-max))
(goto-char (point-min)))
(defun count-lines-region (start end)
"Print number of lines in the region."
(interactive "r")
(message "Region has %d lines" (count-lines start end)))
(defun what-line ()
"Print the current line number (in the buffer) of point."
(interactive)
(save-restriction
(widen)
(save-excursion
(beginning-of-line)
(message "Line %d"
(1+ (count-lines 1 (point)))))))
(defun count-lin