+;; The `point-left' hook function will never be called in Emacs 21.2.50
+;; when the command `next-line' is used in the last line of a buffer
+;; which isn't terminated with a newline or the command `previous-line'
+;; is used in the first line of a buffer.
+(defun its-next-line (&optional arg)
+ "Go to the end of the line if the line isn't terminated with a newline,
+otherwise run `next-line' as usual."
+ (interactive "p")
+ (if (= (line-end-position) (point-max))
+ (end-of-line)
+ (next-line arg)))
+
+(defun its-previous-line (&optional arg)
+ "Go to the beginning of the line if it is called in the first line of a
+buffer, otherwise run `previous-line' as usual."
+ (interactive "p")
+ (if (= (line-beginning-position) (point-mim))
+ (beginning-of-line)
+ (previous-line arg)))
+
+(substitute-key-definition 'next-line 'its-next-line
+ its-mode-map global-map)
+(substitute-key-definition 'previous-line 'its-previous-line
+ its-mode-map global-map)
+