(defun dot () (point))

(defun hk ()
"Nuke the whole buffer; hk is an old, old twemacs name."
  (interactive)
  (goto-char 0)
  (setq pt (point))
  (goto-char (+ (buffer-size) 1))
  (kill-region pt (point))
)

(defun toggle-var (v-dont-use-this-name)
"Toggle VARIABLE from t to nil and vice versa.  Return its current value, i.e.,
its value after having been toggled."
  (interactive "vVar to toggle: ")
  (if (null (eval v-dont-use-this-name))
      (set v-dont-use-this-name t)
      (set v-dont-use-this-name nil))
  (message (concat "Current value is " (pp (eval v-dont-use-this-name))))
  (eval v-dont-use-this-name)
)

(defun switch-to-buffer-in-window (w b)
"\n(switch-to-buffer-in-window SIZE:N BUFFER:B) builds a window of selected SIZE
either above or below current window and then switches to BUFFER in that
window.  New window is built out-of current window; i.e., current window will
shrink by size of new window.

Sign of SIZE arg indicates relative position of new window:
    SIZE>0 => below current window,
    SIZE<0 => above current window.
Any errors such as bad window size are handled indirectly by called fcns."
  (interactive "NNew window size: 
BBuffer: ")
	(setq cur-dot (dot))		;Save exact cur char pos.
	(beginning-of-window)		;Save pos of line that is now at
	(setq cur-top (dot))		; top of window.
	(setq wh (window-height))	;Used in computation below.
	(split-window-vertically)	;Leaves cursor in upper window.
	
	;Important Note:  because of how shrink- and enlarge-window work
	; we must do a shrink in the upper window in order to have things
	; work consistently right.
	(if (< w 0)			;If making new win above
	    (setq nw (- 0 w))		; just take abs(w) for use below,
	    (setq nw (- (- wh w) 1))	; else compute w based on orig wh.
	)
	(if (> nw (window-height))	;Make upper window bigger
	    (while (> nw (window-height))
		   (enlarge-window 1))
	    (while (< nw (window-height)); or smaller, as appro.
		   (shrink-window 1))
	)
	(if (< w 0)			;Stay in or switch to orig window.
	    (other-window 1))
;	(goto-char cur-top)		;Make sure orig line at top
;	(line-to-top-of-window)		; stays there, and
;	(goto-character cur-dot)	; restore exact orig char pos.
	(if (< w 0)			;Switch to new window.
	    (previous-window)
	    (other-window 1)
	)
	(switch-to-buffer b)		;Switch to selected buffer.
	;NB: no new buff name => a blank buf, but not THE null buf.
)

(defun move-over-whitespace ()
"Move forward over any whitespace chars in front of dot."
    (interactive)
    (while (or (equal (following-char) ? )
	       (equal (following-char) ?\t)
	       (equal (following-char) ?\n))
	(forward-char 1)
    )
)

(defun move-backward-over-whitespace ()
"Move forward over any whitespace chars in behind dot."
  (interactive)
    (while (or (equal (preceding-char) ? )
	       (equal (preceding-char) ?\t)
	       (equal (preceding-char) ?\n))
	(backward-char 1)
    )
)

(defun delete-whitespace ()
"Delete any whitespace chars around dot."
  (interactive)
  (while (or (equal (following-char) ? ) (equal (following-char) ?\t))
    (delete-char 1))
  (while (or (equal (preceding-char) ? ) (equal (preceding-char) ?\t))
    (delete-char -1))
)

(defun delete-blank-lines ()
"Redefinition of built-in emacs version.
On blank line, delete all surrounding blank lines, leaving none.
At beginning of nonblank line, delete any immediately preceding blank lines.
On nonblank line, even if at end, do NOT delete any immediately following blank
lines."
    (interactive)
    
    (while (and (= (current-column) 0) (= (following-char) ?\n))
        (delete-char 1)
    )
    (setq done nil)
    (while (and (not done) (= (preceding-char) ?\n))
        (backward-char 1)
	(if (= (current-column) 0)
    	    (delete-char 1)
	    (progn
	      (forward-char 1)
	      (setq done t)
	    )
	)
    )
)