(defun dot () (point)) ; Got rid of the following in v24 since it ain't got gensym no more. ; (defmacro ignore-errors (&rest body) ; "Execute FORMS; if an error occurs, return nil. ; Otherwise, return result of last FORM." ; (let ((err (gensym))) ; (list 'condition-case err (cons 'progn body) '(error nil)))) (require 'mlsupport) (defun paranoid-save-buffer () (interactive) ;Just do a save-buffer if the user is not gfisher and we're not on aix. (if (or (not (string= (user-login-name) "gfisher")) (aix-p)) (save-buffer) (paranoid-save-buffer1) ) ) (defun paranoid-save-buffer1 () (interactive) ; (let x (defvar buf-file-name nil "*") (defvar root-file-name nil "*") (defvar other-host nil "*") (cond ( (buffer-modified-p) (save-buffer) ;Do this just once at load time to avoid slowing save everytime it's called. ; (setq other-host (shell-command-to-string-one-line ; "printenv otherhost")) (setq buf-file-name buffer-file-name) (temp-switch-to-buffer "X") (hk) (insert-string buf-file-name) (goto-char 0) (if (search-forward "fisher" nil t) (progn (backward-word 1) (setq pt (point)) (goto-char (+ (buffer-size) 1)) (setq root-file-name (buffer-substring pt (point))) (switch-back-from-temp-buffer) (start-process "rcp-write" "rcp-write" "scp" buf-file-name (concat other-host ":/home/faculty1/" root-file-name)) (temp-switch-to-buffer "rcp-write") (end-of-buffer) (insert (concat " " (current-time-string) "\n")) (switch-back-from-temp-buffer) (process-kill-without-query (get-process "rcp-write")) ) (switch-back-from-temp-buffer) ) ) (t (message "(No changes need to be saved)") ) ) ; ) ) (defun temp-switch-to-buffer (b) "Temporarily switch to a buffer, typically to grab the contents of some command output that's put in a buffer rather than provided as function output. See also switch-back-from-temp-buffer." (setq --buffer-temp-switched-from (buffer-name)) (interactive "sTemp switch to buffer: ") (switch-to-buffer b) ) (defvar --buffer-temp-switched-from nil "*See doc of function switch-to-temp-buffer") (defun switch-back-from-temp-buffer () "Switch back to the buffer from which the most recent temp-switch-to-buffer (q.v.) was issued. Note well that temp switches are not stacked, so if two temp-switches are executed in a row, only the most recent will be switch-backable to." (interactive) (switch-to-buffer --buffer-temp-switched-from) ) (defun shell-command-to-string (sh-command) "Execute shell-command, grab result from buffer *Shell Command Output* and return as string." (interactive "sShell Command: ") ; (let rtrn-val (save-window-excursion (shell-command sh-command) (temp-switch-to-buffer "*Shell Command Output*") (goto-char 0) (setq pt (point)) (goto-char (+ (buffer-size) 1)) (setq rtrn-val (buffer-substring pt (point))) (switch-back-from-temp-buffer) (princ rtrn-val) ) ; ) ) (defun shell-command-to-string-one-line (sh-command) "Just like shell-command-to-string, but just grab first line of output. In particular, it gets rid of the '^J' char at the end of the line." (interactive "sShell Command: ") ;(let rtrn-val pt (save-window-excursion (shell-command sh-command) (temp-switch-to-buffer "*Shell Command Output*") (goto-char 0) (setq pt (point)) (end-of-line) (setq rtrn-val (buffer-substring pt (point))) (switch-back-from-temp-buffer) (princ rtrn-val) ) ;) ) (defun mark-whole-buffer-save-excursion () "Run mark-buffer with save-excursion." (save-excursion (goto-char 0) (set-mark (point)) (goto-char (+ (buffer-size) 1)) ) ) ; OK, so there's a built-in getenv! ;(defvar other-host (shell-command-to-string-one-line "printenv otherhost") ; "*value of 'printenv otherhost'") (defvar other-host (getenv "otherhost") "*value of 'printenv otherhost'")