1 ;;; misc.el --- some nonstandard basic editing commands for Emacs
3 ;; Copyright (C) 1989, 2001, 2002, 2003, 2004, 2005,
4 ;; 2006, 2007, 2008, 2009 Free Software Foundation, Inc.
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 of the License, or
14 ;; (at your option) 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. If not, see <http://www.gnu.org/licenses/>.
28 (defun copy-from-above-command (&optional arg
)
29 "Copy characters from previous nonblank line, starting just above point.
30 Copy ARG characters, but not past the end of that line.
31 If no argument given, copy the entire rest of the line.
32 The characters copied are inserted in the buffer before point."
34 (let ((cc (current-column))
40 (skip-chars-backward "\ \t\n")
42 ;; Default is enough to copy the whole rest of the line.
43 (setq n
(if arg
(prefix-numeric-value arg
) (point-max)))
44 ;; If current column winds up in middle of a tab,
45 ;; copy appropriate number of "virtual" space chars.
46 (if (< cc
(current-column))
47 (if (= (preceding-char) ?
\t)
49 (setq string
(make-string (min n
(- (current-column) cc
)) ?\s
))
50 (setq n
(- n
(min n
(- (current-column) cc
)))))
51 ;; In middle of ctl char => copy that whole char.
53 (setq string
(concat string
56 (min (save-excursion (end-of-line) (point))
60 ;; Variation of `zap-to-char'.
62 (defun zap-up-to-char (arg char
)
63 "Kill up to, but not including ARGth occurrence of CHAR.
64 Case is ignored if `case-fold-search' is non-nil in the current buffer.
65 Goes backward if ARG is negative; error if CHAR not found.
66 Ignores CHAR at point."
67 (interactive "p\ncZap up to char: ")
68 (let ((direction (if (>= arg
0) 1 -
1)))
71 (forward-char direction
)
73 (search-forward (char-to-string char
) nil nil arg
)
74 (backward-char direction
))
77 ;; These were added with an eye to making possible a more CCA-compatible
78 ;; command set; but that turned out not to be interesting.
80 (defun mark-beginning-of-buffer ()
81 "Set mark at the beginning of the buffer."
83 (push-mark (point-min)))
85 (defun mark-end-of-buffer ()
86 "Set mark at the end of the buffer."
88 (push-mark (point-max)))
90 (defun upcase-char (arg)
91 "Uppercasify ARG chars starting from point. Point doesn't move."
94 (upcase-region (point) (progn (forward-char arg
) (point)))))
96 (defun forward-to-word (arg)
97 "Move forward until encountering the beginning of a word.
98 With argument, do this that many times."
100 (or (re-search-forward (if (> arg
0) "\\W\\b" "\\b\\W") nil t arg
)
101 (goto-char (if (> arg
0) (point-max) (point-min)))))
103 (defun backward-to-word (arg)
104 "Move backward until encountering the end of a word.
105 With argument, do this that many times."
107 (forward-to-word (- arg
)))
111 "Use butterflies to flip the desired bit on the drive platter.
112 Open hands and let the delicate wings flap once. The disturbance
113 ripples outward, changing the flow of the eddy currents in the
114 upper atmosphere. These cause momentary pockets of higher-pressure
115 air to form, which act as lenses that deflect incoming cosmic rays,
116 focusing them to strike the drive platter and flip the desired bit.
117 You can type `M-x butterfly C-M-c' to run it. This is a permuted
118 variation of `C-x M-c M-butterfly' from url `http://xkcd.com/378/'."
120 (if (yes-or-no-p "Do you really want to unleash the powers of the butterfly? ")
122 (switch-to-buffer (get-buffer-create "*butterfly*"))
125 (setq indent-tabs-mode nil
)
126 (animate-string "Amazing physics going on..."
127 (/ (window-height) 2) (- (/ (window-width) 2) 12))
128 (sit-for (* 5 (/ (abs (random)) (float most-positive-fixnum
))))
129 (message "Successfully flipped one bit!"))
130 (message "Well, then go to xkcd.com!")
131 (browse-url "http://xkcd.com/378/")))
135 ;; arch-tag: 908f7884-c19e-4388-920c-9cfa425e449b
136 ;;; misc.el ends here