From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Alastair Houghton Newsgroups: gmane.emacs.devel Subject: asm-mode patch to allow per-file comment character setting from file locals Date: Fri, 9 Jun 2006 13:00:37 +0100 Message-ID: <2E2BAEFF-FEAD-4616-87CD-3B77D2734256@alastairs-place.net> NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 (Apple Message framework v750) Content-Type: text/plain; charset=US-ASCII; delsp=yes; format=flowed Content-Transfer-Encoding: 7bit X-Trace: sea.gmane.org 1149867201 13452 80.91.229.2 (9 Jun 2006 15:33:21 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Fri, 9 Jun 2006 15:33:21 +0000 (UTC) Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Fri Jun 09 17:33:16 2006 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by ciao.gmane.org with esmtp (Exim 4.43) id 1Foiyq-0001LM-5Z for ged-emacs-devel@m.gmane.org; Fri, 09 Jun 2006 17:33:00 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Foiyp-0003UD-MG for ged-emacs-devel@m.gmane.org; Fri, 09 Jun 2006 11:32:59 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1Foffg-0004tv-6v for emacs-devel@gnu.org; Fri, 09 Jun 2006 08:01:00 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1Foffe-0004qv-2u for emacs-devel@gnu.org; Fri, 09 Jun 2006 08:00:59 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Foffd-0004qb-U5 for emacs-devel@gnu.org; Fri, 09 Jun 2006 08:00:57 -0400 Original-Received: from [212.159.14.132] (helo=pih-relay05.plus.net) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA:32) (Exim 4.52) id 1Fofng-0005ID-2o for emacs-devel@gnu.org; Fri, 09 Jun 2006 08:09:16 -0400 Original-Received: from [213.162.110.205] (helo=[10.0.1.5]) by pih-relay05.plus.net with esmtp (Exim) id 1FoffL-0007bs-5R for emacs-devel@gnu.org; Fri, 09 Jun 2006 13:00:39 +0100 Original-To: emacs-devel@gnu.org X-Mailer: Apple Mail (2.750) X-Mailman-Approved-At: Fri, 09 Jun 2006 11:32:48 -0400 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:55789 Archived-At: 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