home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / languages / elisp / modes / asm-mode.el < prev    next >
Encoding:
Text File  |  1989-06-18  |  5.1 KB  |  149 lines

  1. ;To: unix-emacs@bbn.com
  2. ;Date: 3 Jan 89 18:20:36 GMT
  3. ;From: Martin Neitzel <mcvax!unido!infbs!neitzel@uunet.uu.net>
  4. ;Subject: asm-mode, incl. nice comment placements.
  5. ;
  6. ;
  7. ;I just hacked up this little asm-mode. ("Oh no!").  Even if you throw
  8. ;the asm-mode itself far away, it might be worthwhile to rip off the
  9. ;function asm-comment, which handles general eol-comments in a nice
  10. ;way.  For example, you could use it for Ada, Icon, and Lisp too.
  11. ;A comment request (triggered by, say, ";") will try to figure out the
  12. ;appropriate kind of comment based on the current context.  If this
  13. ;isn't the kind you want, simply hit ";" again: e.g., a side comment
  14. ;will be promoted to a comment on its own line indented like code and
  15. ;so on.  I like it, but your mileage may vary...
  16. ;
  17. ;Uhhhmmm, yes, I don't know how to elisp...
  18. ;
  19. ;                            Martin
  20. ;---snip---
  21. ;; Asm-mode, and its related commands.
  22. ;; Cloned from text-mode, and therefore the usual prelude is inevitable:
  23.  
  24. ;; Copyright (C) 1985, 1989 Free Software Foundation, Inc.
  25.  
  26. ;; This file is part of GNU Emacs.
  27.  
  28. ;; GNU Emacs is distributed in the hope that it will be useful,
  29. ;; but WITHOUT ANY WARRANTY.  No author or distributor
  30. ;; accepts responsibility to anyone for the consequences of using it
  31. ;; or for whether it serves any particular purpose or works at all,
  32. ;; unless he says so in writing.  Refer to the GNU Emacs General Public
  33. ;; License for full details.
  34.  
  35. ;; Everyone is granted permission to copy, modify and redistribute
  36. ;; GNU Emacs, but only under the conditions described in the
  37. ;; GNU Emacs General Public License.   A copy of this license is
  38. ;; supposed to have been given to you along with GNU Emacs so you
  39. ;; can know your rights and responsibilities.  It should be in a
  40. ;; file named COPYING.  Among other things, the copyright notice
  41. ;; and this notice must be preserved on all copies.
  42.  
  43.  
  44. (defvar asm-mode-syntax-table nil
  45.   "Syntax table used while in asm mode.")
  46.  
  47. (defvar asm-mode-abbrev-table nil
  48.   "Abbrev table used while in asm mode.")
  49. (define-abbrev-table 'asm-mode-abbrev-table ())
  50.  
  51. (if asm-mode-syntax-table
  52.     ()
  53.   (setq asm-mode-syntax-table (make-syntax-table))
  54.   (set-syntax-table asm-mode-syntax-table)
  55.   (modify-syntax-entry ?;    "<   " asm-mode-syntax-table)
  56.   (modify-syntax-entry ?\n    ">   " asm-mode-syntax-table))
  57.  
  58. (defvar asm-mode-map nil "")
  59. (if asm-mode-map
  60.     ()
  61.   (setq asm-mode-map (make-sparse-keymap))
  62.   (define-key asm-mode-map "\t" 'tab-to-tab-stop)
  63.   (define-key asm-mode-map ":" 'asm-colon)
  64.   (define-key asm-mode-map ";" 'asm-comment)
  65.   (define-key asm-mode-map "\C-c\C-c" 'compile)
  66.   (define-key asm-mode-map "\C-c\C-n" 'next-error)
  67.   )
  68.  
  69.  
  70. (defun asm-mode ()
  71.   "
  72. Major mode for editing typical assembler code \(gack!\).  Features:
  73.  
  74. own asm-mode-abbrev-table
  75. \\[asm-colon]\toutdents labels,
  76. \\[asm-comment]\tmakes placement of comments a fun game.
  77.  
  78. Turning on asm-mode calls the value of the variable asm-mode-hook,
  79. if that value is non-nil.  You probably want to redefine the
  80. variables comment-start and comment-start-skip there.
  81.  
  82. Special commands:\\{asm-mode-map}
  83. "
  84.  
  85.   (interactive)
  86.   (kill-all-local-variables)
  87.   (use-local-map asm-mode-map)
  88.   (setq mode-name "Asm")
  89.   (setq major-mode 'asm-mode)
  90.   (setq local-abbrev-table asm-mode-abbrev-table)
  91.   (set-syntax-table asm-mode-syntax-table)
  92.   (make-local-variable 'comment-start)
  93.   (setq comment-start "; ")
  94.   (make-local-variable 'comment-end)
  95.   (setq comment-end "")
  96.   (make-local-variable 'comment-column)
  97.   (setq comment-column 32)
  98.   (make-local-variable 'comment-start-skip)
  99.   (setq comment-start-skip ";+[ \t]*")
  100.   ; (make-local-variable 'comment-indent-hook)
  101.   ; (setq comment-indent-hook 'c-comment-indent)
  102.   (auto-fill-mode 1)
  103.   (run-hooks 'asm-mode-hook))
  104.  
  105.  
  106. (defun asm-colon ()
  107.   "Insert a colon, and delete the indentation iff it follows a label."
  108.   (interactive)
  109.   (save-excursion
  110.     (beginning-of-line)
  111.     (if (looking-at "[ \t]+\\(\\sw\\|\\s_\\)+$")
  112.     (delete-horizontal-space)))
  113.   (insert ":"))
  114.  
  115. (defun asm-comment ()
  116.   "Introduce a comment or convert an already existing comment into a
  117. comment of a `bigger' kind.  These are the known comment classes:
  118.  
  119.     1-- to the right of the code (at the comment-column)
  120.     2-- comment on a own line, indented like code
  121.     3-- at the left-most column.
  122.  
  123. Suggested usage:  while writing your code, trigger asm-comment
  124. repeatedly until you are satisfied with the kind of comment."
  125.  
  126.   (interactive)
  127.   ;; on a blank line, do nothing nothing special
  128.   (if (eq (current-column) (current-indentation))
  129.       (insert comment-start)
  130.     ;; There is already something on the line.
  131.     ;; If we NOT already have a comment, indent for a new one.
  132.     (beginning-of-line)
  133.     (if (not (looking-at (concat ".*" (regexp-quote comment-start))))
  134.     (indent-for-comment)
  135.       ;; There is a comment, convert it to a `bigger' class.
  136.       (end-of-line)
  137.       (search-backward comment-start)
  138.       (delete-horizontal-space)
  139.       (if (= (current-column) (current-indentation))
  140.       () ;; was code level, --> col-1-comment
  141.     ;; was right to code
  142.     (newline-and-indent))
  143.       (end-of-line))))
  144. ;--
  145. ;Martin Neitzel,  Techn. Univ. Braunschweig, W.Germany
  146. ;BITNET/EARN:    neitzel@dbsinf6.bitnet      (mail via bitnet preferred)
  147. ;UUCP:        neitzel@infbs.uucp  (unido!infbs!neitzel)
  148.  
  149.