From: Alastair Houghton <alastair@alastairs-place.net>
Subject: asm-mode patch to allow per-file comment character setting from file locals
Date: Fri, 9 Jun 2006 13:00:37 +0100 [thread overview]
Message-ID: <2E2BAEFF-FEAD-4616-87CD-3B77D2734256@alastairs-place.net> (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
next reply other threads:[~2006-06-09 12:00 UTC|newest]
Thread overview: 37+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-06-09 12:00 Alastair Houghton [this message]
2006-06-11 21:20 ` asm-mode patch to allow per-file comment character setting from file locals 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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=2E2BAEFF-FEAD-4616-87CD-3B77D2734256@alastairs-place.net \
--to=alastair@alastairs-place.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).