;;;-*-EMACS-LISP-*- ;;; ;;; Copyright 1988, 1989, 1990, 1991, 1992, 1993, 1994 Leigh L. Klotz, Jr. ;;; All Rights Reserved. ;;; ;;; Toggle Auto Fill. ;;; This ought to be in standard EMACS. ;;; I put it on ^X-^A, and have since 1979. (defun toggle-auto-fill (arg) "If given on argument, toggle auto fill mode. With a positive argument, set fill column to that number and turn on fill mode. With a negative argument, turn it off." (interactive "p") (cond ((null current-prefix-arg) (auto-fill-mode nil)) (t (auto-fill-mode arg) (if (> arg 0) (set-fill-column arg)))) nil) ;;; I sometimes like to use RETURN in auto fill mode, ;;; and the default definition on occasion gives two ;;; returns. So, I put this on return. (defun newline-no-break (arg) "Insert a newline. With arg, insert that many newlines. In Auto Fill mode, this function, unlike newline, will not break the preceding line." (interactive "p") (newline arg)) ;;; ^X-# from JAR (paraphrase) (defvar insert-count-and-increment-counter 1) (defun insert-count-and-increment (&optional new-value) "Insert and increment the value of insert-count-and-increment-counter With a prefix argument, set the value of insert-count-and-increment-counter instead." (interactive "p") (cond ((null current-prefix-arg) (insert (int-to-string insert-count-and-increment-counter)) (setq insert-count-and-increment-counter (1+ insert-count-and-increment-counter))) (t (setq insert-count-and-increment-counter new-value)))) ;;; useful in keyboard macros. (defun increment-value-at-point (n) "Increment the number after point. With an argument, add that much." (interactive "p") (save-excursion (let (val) (delete-region (point) (progn (setq val (read (current-buffer))) (if (not (numberp val)) (error "Not in front of a number")) (point))) (insert (int-to-string (+ val n)))))) (defun get-value-at-point () "Get the number after point." (interactive "") (save-excursion (read (current-buffer)))) (defun get-and-delete-value-at-point () "Get the number after point and remove it" (interactive "*") (save-excursion (let* ((here (point)) (value (read (current-buffer)))) (delete-region here (point)) value))) (defun insert-value-at-point (n) "Insert the number at point" (interactive "*pNumber: ") (save-excursion (insert (number-to-string n)))) (defun modify-value-at-point (expression) "Eval expression with 'x' bound to number at, and replace it with returned value." (interactive "*sExpression: ") (let ((x (get-and-delete-value-at-point))) (insert-value-at-point (eval (if (stringp expression) (read expression) expression))))) ;;;; ;;;; M-X Insert Date ;;;; (defun insert-date () "Inserts the current date and time." (interactive "*") (insert (current-time-string))) ;;;;;;;;;;;;;;;;;;;;;;;;; ;;;insert-boxed-string;;; ;;;;;;;;;;;;;;;;;;;;;;;;; (defun insert-boxed-string (string box) "Asks for you string and box. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;\\[insert-boxed-string];;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;" (interactive "*sString: \nsBox: ") (let* ((lbox (length box)) (w-c (+ (* 2 lbox) (length string))) (reps (/ w-c lbox)) (leftover (substring box 0 (mod w-c lbox)))) (dotimes (i reps) (insert box)) (insert leftover) (insert "\n") (insert box) (insert string) (insert box) (insert "\n") (dotimes (i reps) (insert box)) (insert leftover) (insert "\n"))) (defun supergrep (regexp dir file-globexp) (interactive (list (read-string "Find string (regexp): ") (read-directory-name "Recursively, in directory: ") (read-string "In files matching (use ?*[]): "))) (let ((default-directory dir)) (compile-internal (format "find . -name %s -exec grep -n %s {} /dev/null \\;" (regexp-quote file-globexp) ;not quite right regexp) "No more matches" "supergrep" nil grep-regexp-alist)))