help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: At&t assembler syntax highlighting


From: Xah
Subject: Re: At&t assembler syntax highlighting
Date: Thu, 20 Nov 2008 22:23:18 -0800 (PST)
User-agent: G2/1.0

On Nov 19, 10:13 pm, Alexander <coo...@gmail.com> wrote:
> Xahпишет:> On Nov 18, 10:46 pm, Alexander<coo...@gmail.com>  wrote:
>
> > don't know.
>
> > but if you produce a list of function names, type names, keyword
> > names, etc, i can produce the mode for you.
>
> >    Xah
> > ∑http://xahlee.org/
>
> It will be good.
>
> asm-mode quite pretty highlights source code, but it is not able to add 
> comments for at&t assembler.
> comments for at&t assembler are added in following way:
> # this is a comment
> /* this is a comment */
> but in current asm-mode, comments added with ";;".
>
> Could give me some examples, how to change comments format for this mode?
> Thanks.

you'll have to do several things:

• modify the syntax table of that mode, using a hook.
• possibly modify the the keymap in that mode, using a hook, so that
the shortcut for comment-dwim do comment.

the mode is probably not very well written since it gets the comment
wrong. So the best thing is to either contact the author to have him
fix these, or just modify the mode' source code yourself and become
the maintainer/fork yourself.

Here's a example how to modify the syntax table using a hook, so that
the char “-” in elisp mode is considered part of word, so that cursor
movement will move a whole something-something instead of stopping at
“_”.

(add-hook 'emacs-lisp-mode-hook
 (lambda ()
  (modify-syntax-entry ?- "w" emacs-lisp-mode-syntax-table )
 )
)

the essense of using a hook to modify a mode's syntax table, is that
you need to find the hook name and syntax table name. If the mode name
is xyz-mode, its hook name is usually xyz-mode-hook and xyz-mode-
syntax-table.

To find out the mode's mode name, do Ctrl+h v then type major-mode.

Here's a example of modifying the source code on the syntax table
itself:

(defvar xlsl-mode-syntax-table
  (let ((synTable (make-syntax-table)))
    (modify-syntax-entry ?\/ ". 12b" synTable)
    (modify-syntax-entry ?\n "> b" synTable)
    synTable
    )
  "Syntax table for `xlsl-mode'."
)

in this case, the lsl lang's comment is

// this is comment
/* this is NOT comment */

the emacs's syntax table concept and code is rather esoteric... i'm
thinking it's that useful, or rather not powerful and flexible enough.

in your case, you probably want

    (modify-syntax-entry ?# ". 12b" synTable)
    (modify-syntax-entry ?\n "> b" synTable)

to cover the
# comment

 i haven't wrote a mode that deal with comment like:
/* comment here */

but basically 2 lines like the above will do. See

• Syntax Class Table - GNU Emacs Lisp Reference Manual
http://xahlee.org/elisp/Syntax-Class-Table.html

• Syntax Flags - GNU Emacs Lisp Reference Manual
http://xahlee.org/elisp/Syntax-Flags.html

the latter has some comments on how to do the “/* comment */”.

------------------------

maybe later today i'll write a full tutorial on how do deal with the 2
types of comments, one starts with a line and ends in a EOL, and the
other using matching pairs.


look at java mode's source code, since that lang uses the same as your
case.

--------------

if you find the above too hard, you can just resort to

C-x r k runs the command kill-rectangle
C-x r t runs the command string-rectangle

for the first 5 years of using emacs, i just used these for comments,
in any lang.

  Xah
∑ http://xahlee.org/

reply via email to

[Prev in Thread] Current Thread [Next in Thread]