Re: How to enable Semantic for temp buffer

Tu Do <[email protected]> Wed, 8 Apr 2015 18:54:17 +0700
Newsgroups gmane.emacs.cedet
Message-ID <CAOEd9j=xp=pLxA=WE8vC4ZYc=O2+or63PcssQTEmETTQxc4DeQ@mail.gmail.com>
>
> This is pretty cool.  Do you think the core bit would translate easily to
> other languages?
>

As of now Srefactor can now format generic Lisp code, even Lisp code in
fundamental mode thanks to the robustness of Semantic lexer. Now it
supports Scheme, Common Lisp and Clojure (propably other Lisps as well, as
long as code are built around sexp with parenthese). Here is a Clojure
demo: http://i.imgur.com/puTmYJL.gif

I will add Common Lisp and Scheme demos soon.

I always assumed most languages needed the parser as well.
>

And yes, I do believe so. A framework like Semantic could potential make
Emacs becomes an IDE with superb text editing capacity. Sadly, people just
ignore it.  Some people expect Emacs has something similar to Xtext:
https://eclipse.org/Xtext/, yet we already have CEDET here. I used Xtext a
few years ago to add support for an in-house language; surely it is not as
enjoyable with Semantic. It's painful working with Java and Eclipse.

Thank you for creating this wonderful piece of software to make this
possible.

Tu.

On Wed, Apr 8, 2015 at 10:11 AM, Tu Do <[email protected]> wrote:

> It works fine for me after I put (semantic-lex-init) before doing any
> lexing in temp buffer. The good news is, now it can even work for Common
> Lisp, out of the box without doing anything!
>
> Scheme also works but since it does not have much overlap as Common Lisp
> and Emacs Lisp, it's less polished but usable with small and simple defun
> and sexp (Srefactor can format any sexp at point and its sub-sexp
> recursively, not just whole buffer and defun).
>
> 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.
>>
>
> This is awesome. Thank you very much, Eric.
>
>
> On Wed, Apr 8, 2015 at 7:41 AM, Eric Ludlam <[email protected]> wrote:
>
>> 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

_______________________________________________
Cedet-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/cedet-devel