;; $Id: misc.el,v 1.1 2007/11/29 04:33:11 tag Exp $ ;; ;;; misc.el - miscellaneous routines ;;; ;;; by Tim Gonsalves, 30-Nov-88 ;;; ;;; $Log: misc.el,v $ ;;; Revision 1.1 2007/11/29 04:33:11 tag ;;; Deleted previou-window ;;; ;;; Revision 1.4 2000/05/12 10:28:47 tag ;;; Added (provide 'misc) ;;; ;;; Revision 1.3 2000/05/12 09:45:05 tag ;;; Added delete-whitespace ;;; ;;; Revision 1.2 1999/10/20 12:27:02 tag ;;; Minor bug in my-mark-words (newline was wrapping) ;;; ;;; Revision 1.1 1999/10/20 12:10:20 tag ;;; Added my-mark-words to highlight words, e.g. in e-mail replies ;;; ;;; TAG, 29/11/07: removed interactive previous-window as it clashes ;;; with builtin command. Use '(lambda() (interactive) ;;; (other-window -1)) instead. ;;; TAG, 23/12/98: added my-underline-line ;;; TAG, 11/01/99: modified my-underline-line to add a newline ;;; TAG, 6/08/99: added previous-window ;;; delete-whitespace -- delete spaces, tabs and newlines around point (message "delete-whitespace") (defun delete-whitespace (&optional arg) "Delete all spaces, tabs and newlines around point, leaving arg newlines. Default arg is 1." (interactive "p") (skip-chars-backward " \t\n") (delete-region (point) (progn (skip-chars-forward " \t\n") (point))) (if (not arg) (setq arg 1)) (while (> arg 0) (insert "\n") (setq arg (- arg 1)))) ;;; my-mark-words -- mark words with ^^^^ on the next line (defvar my-mark-char "^" "*Character used by \\[my-mark-words] for marking words.") (defun my-mark-words (arg) "Mark the word containing the cursor with ^^^ on the next line, inserting a blank line for the mark. With an argument, marks several words before the cursor (after the cursor if the argument is negative). Marks only upto the ends of the line." (interactive "p") (let ((startcol) (endcol) ; columns to start and end marking (start) (end) ; point of start/end words to be marked ; (may be on other lines) (linestart) (lineend) ; point of line boundaries (cursor (point))) ; initial point (save-excursion ; find start/end columns and points (if (> arg 0) (progn (and (eq (char-syntax (char-after (point))) ?w) (forward-word 1)) ; if on 1st char of word, we want to ; mark this as the first word (forward-word (- arg)) (setq startcol (current-column)) (setq start (point)) (forward-word arg) (setq endcol (current-column)) (setq end (point))) (progn ; negative arg => mark forwards (forward-word (- arg)) (setq endcol (current-column)) (setq end (point)) (forward-word arg) (setq startcol (current-column)) (setq start (point)))) ; find start/end of this line (goto-char cursor) (beginning-of-line) (setq linestart (point)) (end-of-line) (setq lineend (point)) ; ensure we stay in this line (if (< start linestart) (progn (setq start linestart) (setq startcol 0))) (if (> end lineend) (progn (setq end lineend) (goto-char end) (setq endcol (current-column)))) ) ; (save-excursion...) ; Check that word(s) are around cursor (if (and (<= start cursor) (>= end cursor) (not (= start end))) (progn (end-of-line) (newline 1) (while (> startcol (current-column)) (insert " ")) (while (< startcol endcol) (insert my-mark-char) (setq startcol (+ startcol 1)))) (message "The cursor is not in a word")))) ;;; my-underline-line -- underline text using 2 lines for screen display. ;;; Note: underline-region uses ^H_ for printing, ;;; but is hard to read on-screen (defun my-underline-line (arg) "If point is on a non-empty line, draws a line under it, else draws a line under the previous line. Starts at the first non-blank character. Leaves the cursor on the start of a newline after the underline. \tBy default, uses '----', \twith 1 \\[universal-argument], uses '====', \twith 2 \\[universal-argument]'s, uses '....', \twith 3 \\[universal-argument]'s, uses '____'" (interactive "p") (let ((len 0) (uchar (or (cdr (assoc arg '((4 . "=") (16 . ".") (64 . "_")))) "-")) (lim 0) (startcol 0)) (if (not (and (bolp) (eolp))) (progn ; not an empty line (end-of-line) (newline))) ; append an empty line (beginning-of-line 0) ; beginning of line to be underlined (end-of-line) (setq lim (point)) (beginning-of-line) (skip-chars-forward " \t" lim) (setq startcol (current-column)) (end-of-line) (setq len (- (current-column) startcol)) ; cursor is at start of an empty line, insert ; len underline characters (beginning-of-line 2) ; move to empty line to draw (while (> startcol 0) (insert " ") (setq startcol (- startcol 1))) (while (> len 0) (insert uchar) (setq len (- len 1))) (newline))) (defun my-save-buffer (arg) "If the buffer-name begins with '*', refuses to save it in a file (use \\[write-file] instead). Otherwise, calls save-buffer." (interactive "P") (if (string= (substring (buffer-name) 0 1) "*") (message "If you really want to save this special buffer in a file, use C-x C-w") (save-buffer arg))) (defun scroll-other-window-down (arg) "Scroll next window downward ARG lines; or near full screen if no ARG. A near full screen is `next-screen-context-lines' less than a full screen. The next window is the one below the current one; or the one at the top if the current one is at the bottom." (interactive "p") (if (= arg 1) (scroll-other-window '-) (scroll-other-window (- arg)))) (provide 'misc) ;;; End of misc.el ---------------- End of misc.el ----------------