home bbs files messages ]

Forums before death by AOL, social media and spammers... "We can't have nice things"

   comp.editors      What? Edlin ain't good enough for you?      123,932 messages   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]

   Message 123,408 of 123,932   
   Lawrence D'Oliveiro to All   
   Autosetting Tab-Expansion Mode   
   19 Mar 24 07:05:46   
   
   From: ldo@nz.invalid   
      
   I have gone off putting tabs in source files; so I normally have   
   things set so that pressing the tab key inserts the right number of   
   spaces to take the position to the next tab stop.   
      
   However, when working with files from other sources that already have   
   tabs in them, it is handy to be able to remain compatible by having   
   the tab key insert a tab in those files, without any special checking   
   on my part.   
      
   Here is a hook for Emacs that automatically runs every time a file is   
   opened; it does a quick sniff around to see if it can spot any tabs,   
   and if it does, then it sets the tab key to insert a tab, otherwise it   
   sets it to insert spaces.   
      
   (add-hook 'find-file-hook   
       (lambda ()   
           "sets tab expansion depending on whether the current buffer contains   
   tabs."   
           (save-excursion   
               ; check text within the region of point; if tabs are found, then   
               ; indent with tabs, else indent with spaces   
               (let   
                   (   
                       (checkamt 2048) ; how much text to check   
                   )   
                   (when (<= (point-max) (+ (point) checkamt))   
                       (goto-char   
                           (cond   
                               ((>= (point-max) checkamt)   
                                   (- (point-max) checkamt)   
                               )   
                               (t   
                                   (point-min)   
                               )   
                           ) ; cond   
                       ) ; goto-char   
                   ) ; when   
                   (setq indent-tabs-mode (search-forward "\t" (+ (point)   
   checkamt) t))   
               ) ; let   
           ) ; save-excursion   
       ) ; lambda   
   ) ; add-hook   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]


(c) 1994,  bbs@darkrealms.ca