all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* asm-mode patch to allow per-file comment character setting from file locals
@ 2006-06-09 12:00 Alastair Houghton
  2006-06-11 21:20 ` Stefan Monnier
  2006-06-13 12:19 ` Masatake YAMATO
  0 siblings, 2 replies; 37+ messages in thread
From: Alastair Houghton @ 2006-06-09 12:00 UTC (permalink / raw)


Hi there,

Here's a short patch to asm-mode.el that I use so that I can easily  
vary the comment style used for assembly language files on a per-file  
basis.  This is particularly useful on Mac OS X, where the Intel and  
PowerPC versions of the system assembler use different comment  
characters (I believe the PowerPC version actually accepts both ';'  
and '#', but the Intel one certainly requires '#').

An example of its use:

   ###
   ### Local Variables:
   ### asm-comment-char: ?\#
   ### End:
   ###

Here's the patch:

--- asm-mode.el.prev    2006-06-09 12:26:09.000000000 +0100
+++ asm-mode.el 2006-06-09 12:54:01.000000000 +0100
@@ -59,6 +59,14 @@
    "*The comment-start character assumed by Asm mode."
    :type 'character
    :group 'asm)
+(make-variable-buffer-local 'asm-comment-char)
+(put 'asm-comment-char 'safe-local-variable t)
+
+(defvar asm-current-comment-char nil
+  "Holds the current comment-start character in use in this buffer.")
+(make-variable-buffer-local 'asm-current-comment-char)
+
+(add-hook 'find-file-hook (lambda () (asm-set-comment-char asm- 
comment-char)))

(defvar asm-mode-syntax-table
    (let ((st (make-syntax-table)))
@@ -134,12 +142,9 @@
    ;; Make our own local child of asm-mode-map
    ;; so we can define our own comment character.
    (use-local-map (nconc (make-sparse-keymap) asm-mode-map))
-  (local-set-key (vector asm-comment-char) 'asm-comment)
+  (asm-set-comment-char asm-comment-char)
    (set-syntax-table (make-syntax-table asm-mode-syntax-table))
-  (modify-syntax-entry asm-comment-char "<")

-  (make-local-variable 'comment-start)
-  (setq comment-start (string asm-comment-char))
    (make-local-variable 'comment-add)
    (setq comment-add 1)
    (make-local-variable 'comment-start-skip)
@@ -151,6 +156,22 @@
    (setq fill-prefix "\t")
    (run-mode-hooks 'asm-mode-hook))

+(defun asm-set-comment-char (newch)
+  "Set the comment character for the current buffer"
+  (interactive "c")
+  (when asm-current-comment-char
+    (local-unset-key (vector asm-current-comment-char))
+    (modify-syntax-entry asm-current-comment-char
+                        (with-syntax-table asm-mode-syntax-table
+                          (string (char-syntax asm-current-comment- 
char)))))
+  (setq asm-comment-char newch)
+  (setq asm-current-comment-char newch)
+  (local-set-key (vector asm-comment-char) 'asm-comment)
+  (modify-syntax-entry asm-comment-char "<")
+  (setq comment-start (string asm-comment-char))
+  (when font-lock-mode
+    (font-lock-fontify-buffer)))
+
(defun asm-indent-line ()
    "Auto-indent the current line."
    (interactive)

Kind regards,

Alastair.

--
http://www.alastairs-place.net

^ permalink raw reply	[flat|nested] 37+ messages in thread

end of thread, other threads:[~2006-06-17 17:57 UTC | newest]

Thread overview: 37+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-06-09 12:00 asm-mode patch to allow per-file comment character setting from file locals Alastair Houghton
2006-06-11 21:20 ` Stefan Monnier
2006-06-12  9:46   ` Alastair Houghton
2006-06-12 13:12     ` David Kastrup
2006-06-12 15:02       ` Alastair Houghton
2006-06-12 22:58         ` David Kastrup
2006-06-13 10:36           ` Alastair Houghton
2006-06-13 17:56             ` Eli Zaretskii
2006-06-13 19:27               ` [OT] Netiquette (was: Re: asm-mode patch to allow per-file comment character setting from file locals) Alastair Houghton
2006-06-13 22:21                 ` Thien-Thi Nguyen
2006-06-14 11:25                   ` Alastair Houghton
2006-06-14  3:30                 ` Eli Zaretskii
2006-06-14 10:53                   ` Alastair Houghton
2006-06-14 12:04                     ` [OT] Netiquette David Kastrup
2006-06-14 15:31                       ` Alastair Houghton
2006-06-14 15:43                         ` Sam Steingold
2006-06-14 16:28                           ` Alastair Houghton
2006-06-14 16:35                             ` Sam Steingold
2006-06-14 18:09                             ` Thien-Thi Nguyen
2006-06-14 16:17                         ` Chong Yidong
2006-06-14 16:26                         ` David Kastrup
2006-06-14 16:40                           ` Alastair Houghton
2006-06-14 17:32                             ` Sam Steingold
2006-06-15  8:30                               ` Richard Stallman
2006-06-15  8:57                                 ` Alastair Houghton
2006-06-16  6:01                                   ` Richard Stallman
2006-06-16 18:48                                     ` asm-mode comment char patch (was: [OT] Netiquette) Alastair Houghton
2006-06-17 17:57                                       ` Richard Stallman
2006-06-15  1:58                         ` [OT] Netiquette Miles Bader
2006-06-14  5:11             ` asm-mode patch to allow per-file comment character setting from file locals Miles Bader
2006-06-14 11:18               ` [OT] Whether those with gnu.org addresses in any way represent FSF (was: Re: asm-mode patch to allow per-file comment character setting from file locals) Alastair Houghton
2006-06-14 12:29                 ` [OT] Whether those with gnu.org addresses in any way represent FSF Miles Bader
2006-06-14 12:33                   ` Alastair Houghton
2006-06-14 12:58                     ` nferrier
2006-06-12 22:58         ` asm-mode patch to allow per-file comment character setting from file locals Thien-Thi Nguyen
2006-06-13 12:19 ` Masatake YAMATO
2006-06-13 23:20   ` Richard Stallman

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.