(diary-face-attrs): Fix type of `width'.
[emacs.git] / lisp / misc.el
blobc4ea7153927747c3f79127137d21b2f04c30d2b4
1 ;;; misc.el --- some nonstandard basic editing commands for Emacs
3 ;; Copyright (C) 1989, 2001, 2002, 2003, 2004, 2005,
4 ;; 2006, 2007, 2008 Free Software Foundation, Inc.
6 ;; Maintainer: FSF
7 ;; Keywords: convenience
9 ;; This file is part of GNU Emacs.
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
13 ;; the Free Software Foundation; either version 3, or (at your option)
14 ;; any later version.
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.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the
23 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
24 ;; Boston, MA 02110-1301, USA.
26 ;;; Commentary:
28 ;;; Code:
30 (defun copy-from-above-command (&optional arg)
31 "Copy characters from previous nonblank line, starting just above point.
32 Copy ARG characters, but not past the end of that line.
33 If no argument given, copy the entire rest of the line.
34 The characters copied are inserted in the buffer before point."
35 (interactive "P")
36 (let ((cc (current-column))
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
51 (setq string (make-string (min n (- (current-column) cc)) ?\s))
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)))
62 ;; Variation of `zap-to-char'.
64 (defun zap-up-to-char (arg char)
65 "Kill up to, but not including ARGth occurrence of CHAR.
66 Case is ignored if `case-fold-search' is non-nil in the current buffer.
67 Goes backward if ARG is negative; error if CHAR not found.
68 Ignores 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)))))
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.
82 (defun mark-beginning-of-buffer ()
83 "Set mark at the beginning of the buffer."
84 (interactive)
85 (push-mark (point-min)))
87 (defun mark-end-of-buffer ()
88 "Set mark at the end of the buffer."
89 (interactive)
90 (push-mark (point-max)))
92 (defun upcase-char (arg)
93 "Uppercasify ARG chars starting from point. Point doesn't move."
94 (interactive "p")
95 (save-excursion
96 (upcase-region (point) (progn (forward-char arg) (point)))))
98 (defun forward-to-word (arg)
99 "Move forward until encountering the beginning of a word.
100 With 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)))))
105 (defun backward-to-word (arg)
106 "Move backward until encountering the end of a word.
107 With argument, do this that many times."
108 (interactive "p")
109 (forward-to-word (- arg)))
111 (provide 'misc)
113 ;;; arch-tag: 908f7884-c19e-4388-920c-9cfa425e449b
114 ;;; misc.el ends here