From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,316008d62b7d637e X-Google-Attributes: gid103376,public From: Matthew Heaney Subject: Re: Emacs Ada-Mode Date: 1998/05/26 Message-ID: #1/1 X-Deja-AN: 356856134 References: <356680b9.18964466@news.geccs.gecm.com> Organization: Network Intensive Newsgroups: comp.lang.ada Date: 1998-05-26T00:00:00+00:00 List-Id: brianorpin@bigfoot.com (Brian Orpin) writes: > What I would like is an extension to the mode to align the colons in > record declarations. > > Anyone done this already? I wrote this today. It aligns the colons in record declarations that aren't too complex. You'll have to have written at least "record", "end record", and one declaration (id/type pair) to use this; otherwise, you'll get mismatch errors. It moves point to the last declaration, so you can use it as you're entering the record components. This isn't very fancy. Let me know if it doesn't meet your needs. Matt ;;; STX (defun mjh-format-record () (interactive) (let (start-of-region end-of-region decl decl-list decl-count (max-len 0)) ;; find "end record;" (beginning-of-line) (re-search-forward "\\ *\\ *;" nil nil) (beginning-of-line) (setq end-of-region (point)) ;; find "record" (re-search-backward "\\" nil nil) (forward-line) (setq start-of-region (point)) ;;; (message (buffer-substring start-of-region end-of-region)) ;; calculate number of declarations in record (setq decl-count (count-lines start-of-region end-of-region)) ;; get rid of tabs, because it messes up calculation of length (untabify start-of-region end-of-region) ;; parse declarations into identifier/type pairs (while (> decl-count 0) ;; terminate search for id/type pair at end of line (this isn't a ;; very sophisiticated parse (end-of-line) ;; parse a declaration of the form " : ;" (let ((eol (point))) (beginning-of-line) (re-search-forward "^\\([ \t]*[A-Za-z][A-Za-z0-9_]*\\)[ \t]*:[ \t]*\\(.*;\\)" eol nil)) ;; create a cons cell to store identifier string (car) and ;; whatever follows the colon (cdr) (setq decl (cons (match-string 1) (match-string 2))) ;;; (message (concat "'" (car decl) "' '" (cdr decl) "'")) ;; prepend the id/type pair to the declaration list (setq decl-list (cons decl decl-list)) ;; calculate length of largest identifier (let ((decl-len (length (car decl)))) (if (> decl-len max-len) (setq max-len decl-len))) ;; advance to the next declaration (forward-line) (setq decl-count (1- decl-count))) ; end of while loop ;; reverse declaration list, so that the order of items matches ;; the order of declarations (setq decl-list (nreverse decl-list)) ;; we've recorded all the declarations (decl-list), now delete ;; text that was there (delete-region start-of-region (point)) ;end-of-region) ;; insert declarations, adding padding to end of each identifier (while decl-list ;; pop identifier/type pair off of declaration list (setq decl (car decl-list)) ;; insert identifier as originally written (insert (car decl)) ;; insert padding characters (insert-char ? (- max-len (length (car decl)))) (insert " : ") ;; insert type (technically, whatever followed colon) (insert (cdr decl)) (insert "\n") (setq decl-list (cdr decl-list))) ; end of while loop ;; move point the end of the last declaration (forward-line -1) (end-of-line))) ; end of mjh-format-record (add-hook 'ada-mode-hook '(lambda () (define-key ada-mode-map "\C-c\C-r" 'mjh-format-record)))