(defvar nmrtr 1 "*for counting in macros (defined by Reuven Ianconescu 9.7.92)") (defun nmrtr-increment (arg) "Increments the variable nmrtr by the value of ARG. Written by Reuven Ianconescu 9.7.92" (interactive "p")(setq nmrtr (+ arg nmrtr))) (defun nmrtr-insert(width) "Inserts to the buffer the value of the variable nmrtr, ARG width field. Written by Reuven Ianconescu 9.7.92" (interactive "p") (insert-string (format (format "%%0%dd" width) nmrtr))) (defun toggle-case-sensitivity() "Written by Reuven Ianconescu 30.11.92" (interactive) (if case-fold-search (progn (set-variable (quote case-fold-search) nil) (message "Case sensitivity on")) (progn (set-variable (quote case-fold-search) t) (message "Case sensitivity off")))) (defun toggle-truncate-lines() "Written by Reuven Ianconescu 18.2.92" (interactive) (cond (truncate-lines (set-variable (quote truncate-lines) nil) (message "line truncation off")) ((not truncate-lines) (set-variable (quote truncate-lines) t) (message "line truncation on")))) (defun lines-truncated-de-facto () (interactive) (or truncate-lines (and truncate-partial-width-windows (<(window-width) 80)))) (defun horizontal-recenter () (interactive) (if (lines-truncated-de-facto) (scroll-left (- (current-column) (/ (window-width) 2) (window-hscroll))))) (defun my-recenter () (interactive) (recenter nil) (horizontal-recenter)) (defun my-forward-char (arg) (interactive "p") (forward-char arg) (if (> (current-column) (+ (- (window-width) 1) (window-hscroll))) (horizontal-recenter))) (defun my-backward-char (arg) (interactive "p") (backward-char arg) (if (< (current-column) (window-hscroll)) (horizontal-recenter))) (defun my-end-of-line (arg) (interactive "p") (end-of-line arg) (if (lines-truncated-de-facto) (progn (if (> (current-column) (+ (- (window-width) 1) (window-hscroll))) (scroll-left (- (current-column) (-(window-width) 2) (window-hscroll))))))) (defun my-beginning-of-line (arg) (interactive "p") (beginning-of-line arg) (if (> (window-hscroll) 0) (scroll-right (window-hscroll)))) (defun my-forward-word (arg) (interactive "p") (forward-word arg) (if (> (current-column) (+ (- (window-width) 1) (window-hscroll))) (horizontal-recenter))) (defun my-backward-word (arg) (interactive "p") (backward-word arg) (if (< (current-column) (window-hscroll)) (horizontal-recenter))) (defun complete-file-name () (interactive) (defvar pattern) (defvar completion) (save-excursion (setq end (point)) (search-backward " ") (forward-char 1) (setq pattern (buffer-substring (point) end))) (setq completion (file-name-completion (file-name-nondirectory pattern) (or (file-name-directory pattern) default-directory))) (if (not (or (if(equal completion t)(message "Sole completion")) (if(equal completion nil)(message "No match")))) (progn (if (equal completion (file-name-nondirectory pattern)) (with-output-to-temp-buffer " *Completions*" (display-completion-list (file-name-all-completions (file-name-nondirectory pattern) (or (file-name-directory pattern) default-directory)))) (progn (backward-delete-char (length(file-name-nondirectory pattern))) (insert completion) (if (buffer-exists-p " *Completions*") (kill-buffer " *Completions*"))))))) ;;((string= temp-completion (car kill-ring-yank-pointer)) ;; (defvar xxx (format "\n%s\n" (file-name-all-completions ;; (car kill-ring-yank-pointer) default-directory))) ;; (beginning-of-line 1) ;; (re-search-forward shell-prompt-pattern) ;; (set-mark-command 1) (end-of-line 1) ;; (copy-region-as-kill (region-beginning) (region-end)) ;; (insert xxx) (insert (car kill-ring-yank-pointer))) (defun complete-c-word () (interactive) (defvar list-of-c-words) (defvar completion) (defvar pattern) (setq list-of-c-words '(("for(;;)") ("return") ("continue") ("break") ("if()") ("else") ("printf(\"\",)") ("fprintf") ("sprintf") ("fgets") ("scanf") ("fscanf") ("sscanf") ("malloc") ("strcpy") ("strcmp") ("define") ("ifdef") ("endif") ("ctype.h") ("curses.h") ("dirent.h") ("dlfcn.h") ("errno.h") ("exportent.h") ("floatingpoint.h") ("kvm.h") ("locale.h") ("math.h") ("memory.h") ("netdb.h") ("nlist.h") ("pwd.h") ("stdio.h") ("stdlib.h") ("string.h") ("time.h") ("ttyent.h") ("unistd.h") ("vfork.h") ("mp.h"))) (set-mark-command nil) (backward-word 1) (exchange-point-and-mark) (setq pattern (buffer-substring (point) (mark))) (setq completion (try-completion pattern list-of-c-words)) (if (or (if (equal completion t) (message "Sole completion")) (if (equal completion nil) (message "No completions"))) () (progn (if (string= pattern completion) (message "%s" (all-completions pattern list-of-c-words)) (progn (delete-region (point) (mark)) (insert completion)))))) (defvar prev-buf) (defun emacs-menu () (interactive) (if (file-exists-p "nc.mnu") (progn (switch-to-buffer " *Emacs-menu*") (erase-buffer) (setq list-of-menu-items nil) (progn (find-file "nc.mnu") (while (re-search-forward "^[^\\(\\(^ \\)\\|\\(^ \\)\\|\\(^$\\)\\)]" nil t) (beginning-of-line 1) (setq beg (point)) (end-of-line 1) (setq list-of-menu-items (cons (buffer-substring beg (point)) list-of-menu-items)) (beginning-of-line 2)) (kill-buffer "nc.mnu") (setq prev-buf (current-buffer)) (switch-to-buffer " *Emacs-menu*")) (setq l (reverse list-of-menu-items)) (while l (insert (format "%s\n" (car l))) (setq l (cdr l))) (goto-char (point-min)) (setq mode-name " *Emacs-menu*") (save-excursion (set-buffer prev-buf) (setq last-item last-item-number)) (forward-line last-item)) (message "No file found nc.mnu"))) (defvar last-item-number 0) (defun menu-select-item () (interactive) (beginning-of-line 1)(setq item-number (+(count-lines (point-min) (point))1)) (setq last-item-number (1- item-number)) (setq last-item last-item-number) (save-excursion (set-buffer prev-buf) (make-local-variable 'last-item-number) (setq last-item-number last-item)) (kill-buffer " *Emacs-menu*") (find-file "nc.mnu") (while (> item-number 0) (re-search-forward "^[^\\(\\(^ \\)\\|\\(^ \\)\\|\\(^$\\)\\)]" nil t) (beginning-of-line 2) (setq item-number (- item-number 1))) (save-excursion (if (not (re-search-forward "^[^\\(\\(^ \\)\\|\\(^ \\)\\|\\(^$\\)\\)]" (point-max) t)) (goto-char (point-max))) (beginning-of-line 1) (setq end (point))) (setq list-of-commands nil) (while (< (point) end) (save-excursion (forward-word 1)(backward-word 1) (setq beg (point)) (end-of-line 1) (setq list-of-commands (cons (buffer-substring beg (point)) list-of-commands))) (next-line 1)) (kill-buffer "nc.mnu") (dired-create-interactive-shell) (setq l (reverse list-of-commands)) (while l (insert (format "%s" (car l))) (comint-send-input) (setq l (cdr l)))) (defun byte-compile-this-file() (interactive) (byte-compile-file (buffer-file-name (current-buffer))) ) (defun buffer-exists-p (buffer) "Returns t if buffer BEFFER exists, else returns nil. Written by Reuven Ianconescu." (if (get-buffer buffer) t)) (defun other-window1() (interactive)(other-window 1)) (defun other-window-1() (interactive)(other-window -1)) (defun date() (interactive)(shell-command "date" t) (save-excursion (forward-word 3) (setq beg (point)) (end-of-line 1) (backward-word 1) (setq end (point)) (delete-region beg end) (insert-string ", "))) ;; (forward-word 1)(backward-word 1)(setq beg (point)) ;; (re-search-forward "\\( \\|$\\)")(re-search-backward "[^ ]") ;; (forward-char 1) ;; (setq command (buffer-substring beg (point))) ;; (save-excursion (end-of-line 1) (setq eol (point))) ;; (if (<(point) eol)(progn (re-search-forward "[^ ]") (backward-char))) ;; (setq command-arguments (buffer-substring (point) eol )) ;; (call-process command nil 0 t command-arguments) ;; (shell-command (buffer-substring (point) (mark)) nil) ;; (beginning-of-line 2))