Switch to recommended form of GPLv3 permissions notice.
[bpt/emacs.git] / lisp / misc.el
CommitLineData
896546cd 1;;; misc.el --- some nonstandard basic editing commands for Emacs
6594deb0 2
c90f2757 3;; Copyright (C) 1989, 2001, 2002, 2003, 2004, 2005,
409cc4a3 4;; 2006, 2007, 2008 Free Software Foundation, Inc.
0d20f9a0 5
9750e079 6;; Maintainer: FSF
30764597 7;; Keywords: convenience
9750e079 8
0d20f9a0
JB
9;; This file is part of GNU Emacs.
10
11;; GNU Emacs is free software; you can redistribute it and/or modify
12;; it under the terms of the GNU General Public License as published by
b4aa6026 13;; the Free Software Foundation; either version 3, or (at your option)
0d20f9a0
JB
14;; any later version.
15
16;; GNU Emacs is distributed in the hope that it will be useful,
17;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19;; GNU General Public License for more details.
20
21;; You should have received a copy of the GNU General Public License
b578f267 22;; along with GNU Emacs; see the file COPYING. If not, write to the
086add15
LK
23;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
24;; Boston, MA 02110-1301, USA.
0d20f9a0 25
55535639
PJ
26;;; Commentary:
27
e5167999 28;;; Code:
0d20f9a0
JB
29
30(defun copy-from-above-command (&optional arg)
31 "Copy characters from previous nonblank line, starting just above point.
32Copy ARG characters, but not past the end of that line.
33If no argument given, copy the entire rest of the line.
34The characters copied are inserted in the buffer before point."
35 (interactive "P")
36 (let ((cc (current-column))
37 n
38 (string ""))
39 (save-excursion
40 (beginning-of-line)
41 (backward-char 1)
42 (skip-chars-backward "\ \t\n")
43 (move-to-column cc)
44 ;; Default is enough to copy the whole rest of the line.
45 (setq n (if arg (prefix-numeric-value arg) (point-max)))
46 ;; If current column winds up in middle of a tab,
47 ;; copy appropriate number of "virtual" space chars.
48 (if (< cc (current-column))
49 (if (= (preceding-char) ?\t)
50 (progn
ff26cdfe 51 (setq string (make-string (min n (- (current-column) cc)) ?\s))
0d20f9a0
JB
52 (setq n (- n (min n (- (current-column) cc)))))
53 ;; In middle of ctl char => copy that whole char.
54 (backward-char 1)))
55 (setq string (concat string
56 (buffer-substring
57 (point)
58 (min (save-excursion (end-of-line) (point))
59 (+ n (point)))))))
60 (insert string)))
6594deb0 61
2fd8a18a
LK
62;; Variation of `zap-to-char'.
63
64(defun zap-up-to-char (arg char)
821a311f 65 "Kill up to, but not including ARGth occurrence of CHAR.
2fd8a18a
LK
66Case is ignored if `case-fold-search' is non-nil in the current buffer.
67Goes backward if ARG is negative; error if CHAR not found.
68Ignores CHAR at point."
69 (interactive "p\ncZap up to char: ")
70 (let ((direction (if (>= arg 0) 1 -1)))
71 (kill-region (point)
72 (progn
73 (forward-char direction)
74 (unwind-protect
75 (search-forward (char-to-string char) nil nil arg)
76 (backward-char direction))
77 (point)))))
78
9bccd1e3
JB
79;; These were added with an eye to making possible a more CCA-compatible
80;; command set; but that turned out not to be interesting.
81
82(defun mark-beginning-of-buffer ()
83 "Set mark at the beginning of the buffer."
84 (interactive)
85 (push-mark (point-min)))
86
87(defun mark-end-of-buffer ()
88 "Set mark at the end of the buffer."
89 (interactive)
90 (push-mark (point-max)))
91
92(defun upcase-char (arg)
2fd8a18a 93 "Uppercasify ARG chars starting from point. Point doesn't move."
9bccd1e3
JB
94 (interactive "p")
95 (save-excursion
96 (upcase-region (point) (progn (forward-char arg) (point)))))
97
98(defun forward-to-word (arg)
99 "Move forward until encountering the beginning of a word.
100With argument, do this that many times."
101 (interactive "p")
102 (or (re-search-forward (if (> arg 0) "\\W\\b" "\\b\\W") nil t arg)
103 (goto-char (if (> arg 0) (point-max) (point-min)))))
104
105(defun backward-to-word (arg)
106 "Move backward until encountering the end of a word.
107With argument, do this that many times."
108 (interactive "p")
109 (forward-to-word (- arg)))
110
896546cd
RS
111(provide 'misc)
112
cbee283d 113;; arch-tag: 908f7884-c19e-4388-920c-9cfa425e449b
6594deb0 114;;; misc.el ends here