home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / languages / elisp / misc / pt-wysiwyg.el < prev    next >
Encoding:
Text File  |  1990-07-22  |  2.7 KB  |  80 lines

  1. ;From: lrs@indetech.uucp (Lynn Slater)
  2. ;Newsgroups: gnu.emacs
  3. ;Subject: Re: automatic horizontal scrolling
  4. ;Message-ID: <1989Aug23.210346.28643@indetech.uucp>
  5. ;Date: 23 Aug 89 21:03:46 GMT
  6. ;References: <815@pitstop.West.Sun.COM>
  7. ;Reply-To: lrs@indetech.UUCP (Lynn Slater)
  8. ;Distribution: gnu
  9. ;Organization: Independence Technologies, Inc. Fremont, CA
  10. ;Lines: 72
  11. ;Keywords: scrolling, horizontal
  12. ;
  13. ;> I feel that an interesting feature is missing in gnuemacs: automatic
  14. ;> horizontal scrolling 
  15. ;
  16. ;I have some of this in an enhanced picture mode. point-wysiwyg directly
  17. ;addresses your wish. This and other core functions are included below.
  18.  
  19. (defun move-to-column-force (column)
  20.   "Move to column COLUMN in current line.
  21. Differs from move-to-column in that it creates or modifies whitespace
  22. if necessary to attain exactly the specified column.
  23.  
  24. This version (non-standard) insures that the column is visible,
  25. scrolling if needed."
  26.   (move-to-column column)
  27.   (let ((col (current-column)))
  28.     (if (< col column)
  29.         (indent-to column)
  30.       (if (and (/= col column)
  31.                (= (preceding-char) ?\t))
  32.           (let (indent-tabs-mode)
  33.             (delete-char -1)
  34.             (indent-to col)
  35.             (move-to-column column)))))
  36.   (point-wysiwyg)
  37.   )
  38.  
  39. (defun point-wysiwyg ()
  40.   "scrolls the window horozontally to make point visible"
  41.   (let*  ((min (window-hscroll))
  42.           (max (- (+ min (window-width)) 2))
  43.           (here (current-column))
  44.           (delta (/ (window-width) 2))
  45.           )
  46.     (if (< here min)
  47.         (scroll-right (max 0 (+ (- min here) delta)))
  48.       (if (>= here  max)
  49.           (scroll-left (- (- here min) delta))
  50.         ))))
  51.   
  52. (defun window-wysiwyg-point ()
  53.   "Makes point become the visible point
  54.    Moves point, not the scroll.
  55.    Current version good only for picture mode"
  56.   (interactive)
  57.   (let*  ((min (window-hscroll))
  58.           (max (+ min (window-width)))
  59.           (here (current-column))
  60.           (delta (/ (window-width) 2))
  61.           )
  62.     (if (< here min)
  63.         (move-to-column min)
  64.       (if (>= here  max)
  65.           (move-to-column (- max 3))
  66.         ))))
  67.  
  68.  
  69. ;Now, you just have to get point-wysiwyg called from all commands that move
  70. ;point. :->  I have done this for a variant of picture mode.  There is
  71. ;probably a general way to associate this with the truncate line variable so
  72. ;that if lines are not truncated, point-wysiwig is called by the lower level
  73. ;code, but I have not explored this.
  74. ;
  75. ;===============================================================
  76. ;Lynn Slater -- {sun, ames, pacbell}!indetech!lrs or lrs@indetech.uucp
  77. ;42075 Lawrence Place, Fremont Ca 94538
  78. ;Office (415) 438-2048; Home (415) 796-4149; Fax (415) 438-2034
  79. ;===============================================================
  80.