[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
asm-mode patch to allow per-file comment character setting from file loc
From: |
Alastair Houghton |
Subject: |
asm-mode patch to allow per-file comment character setting from file locals |
Date: |
Fri, 9 Jun 2006 13:00:37 +0100 |
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
- asm-mode patch to allow per-file comment character setting from file locals,
Alastair Houghton <=
- Re: asm-mode patch to allow per-file comment character setting from file locals, Stefan Monnier, 2006/06/11
- Re: asm-mode patch to allow per-file comment character setting from file locals, Alastair Houghton, 2006/06/12
- Re: asm-mode patch to allow per-file comment character setting from file locals, David Kastrup, 2006/06/12
- Re: asm-mode patch to allow per-file comment character setting from file locals, Alastair Houghton, 2006/06/12
- Re: asm-mode patch to allow per-file comment character setting from file locals, Thien-Thi Nguyen, 2006/06/12
- Re: asm-mode patch to allow per-file comment character setting from file locals, David Kastrup, 2006/06/12
- Re: asm-mode patch to allow per-file comment character setting from file locals, Alastair Houghton, 2006/06/13
- Re: asm-mode patch to allow per-file comment character setting from file locals, Eli Zaretskii, 2006/06/13
- [OT] Netiquette (was: Re: asm-mode patch to allow per-file comment character setting from file locals), Alastair Houghton, 2006/06/13
- Re: [OT] Netiquette (was: Re: asm-mode patch to allow per-file comment character setting from file locals), Thien-Thi Nguyen, 2006/06/13