Re: How to enable Semantic for temp buffer
Eric Ludlam <[email protected]> Tue, 07 Apr 2015 20:41:45 -0400
| Newsgroups | gmane.emacs.cedet |
|---|---|
| Message-ID | <[email protected]> |
On 04/06/2015 01:40 PM, Tu Do wrote:
> Hi Eric,
>
> How do I enable Semantic parsing for temporary Emacs Lisp mode?
> Semantic that comes with Emacs 24.4 always returns the error "Buffer
> was not setup for parsing" when I use `with-temp-buffer`, set it to
> Emac Lisp mode and insert some Elisp code in there. I want a temp
> buffer to process some Elisp code, but Semantic prevents me to do that.
Howdy,
All that needs to be done is for the setup function to be run in the
buffer first. This used to happen in the mode hook, but since CEDET was
converted to the new format, I'm not sure how it happens.
A good example is in this function : semantic-c-parse-lexical-token
where you will see a section like this:
;; Hack in mode-local
(activate-mode-local-bindings)
;; Setup C parser
(semantic-default-c-setup)
;; CHEATER! The following 3 lines are from
;; `semantic-new-buffer-fcn', but we don't want to turn
;; on all the other annoying modes for this little task.
(setq semantic-new-buffer-fcn-was-run t)
(semantic-lex-init)
(semantic-clear-toplevel-cache)
(remove-hook 'semantic-lex-reset-functions
'semantic-lex-spp-reset-hook t)
)
It took a bit of effort for me to get it to work the first time.
A much simpler example is in semantic/wisent/calc.el in `wisent-calc'
which has a simpler parser, and also parsers a tmp buffer.
> Btw, I've just made a formatting tool for Emacs Lisp using plain
> Semantic lexer. Here are the demos:
> https://github.com/tuhdo/semantic-refactor/blob/master/srefactor-demos/demos-elisp.org
>
This is pretty cool. Do you think the core bit would translate easily
to other languages? I always assumed most languages needed the parser
as well.
Based on the text on that page I'll guess you will want to learn about
`lisp-indent-function'. It is a function, a variable, AND a property.
Thus you can do:
(get 'semantic-safe 'lisp-indent-function)
to see how many following args should be indented past (or something.)
I'm not sure how it works with 'defun. I only ever used it to better
indent custom functions I write using TAB.
Eric
------------------------------------------------------------------------------
BPM Camp - Free Virtual Workshop May 6th at 10am PDT/1PM EDT
Develop your own process in accordance with the BPMN 2 standard
Learn Process modeling best practices with Bonita BPM through live exercises
http://www.bonitasoft.com/be-part-of-it/events/bpm-camp-virtual- event?utm_
source=Sourceforge_BPM_Camp_5_6_15&utm_medium=email&utm_campaign=VA_SF