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

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

Re: Defining functions on the fly


From: Pascal J. Bourguignon
Subject: Re: Defining functions on the fly
Date: Tue, 16 Jun 2015 11:50:25 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux)

Andreas Röhler <andreas.roehler@easy-emacs.de> writes:

> Am 16.06.2015 um 09:01 schrieb Tassilo Horn:
>> Andreas Röhler <andreas.roehler@easy-emacs.de> writes:
>>
>>>>> i'm probably misunderstanding you, but does:
>>>>>      (defun (intern (concat "current-prefix-" foo) ...
>>>>> do what you need?
>>>> (defalias (intern (concat "current-prefix-" foo) ...) ...) can work, but
>>>> not with defun.  In any case, some concrete example of what he needs to
>>>> do would go a long way.
>>>>
>>>>
>>>>           Stefan
>>> Currently Emacs provides some scheme to fontify source code and some
>>> basic moves: linewise, symbol, word, paragraph, sexp.
>>>
>>> There is no idea of statement, block/loop or expression and a poor
>>> top-level --beginning/end-of-defun.
>> There is: `forward-sexp' and `backward-sexp'.  Although the name sexp is
>> a bit lisp-specific, sexp-based motion has been implemented for more
>> C-like languages, too.  For example, it works well for shell scripts
>
> Unfortunatly couldn't experience this. There are several common cases
> within shell-script, where calls to navigate sexp would raise an
> error.
>
> That's why language-modes have to implement a couple of most basic
> things. See
>
> http://lists.gnu.org/archive/html/emacs-devel/2015-06/msg00013.html
>
> ###
>
> vorhanden() {
>     for i in "blah" "blub";
>     do
>         # some comment (note: for compatibility)
>     if [ ! -x $i ]; then
>
> ###
>
> with cursor last line "if", C-M-b jumps to "for", but should end at "do"
> From "for" ->
>
> Debugger entered--Lisp error: (scan-error "Containing expression ends
> prematurely" 13 13)
>   signal(scan-error ("Containing expression ends prematurely" 13 13))
>   smie-forward-sexp-command(-1)
>   forward-sexp(-1)
>   backward-sexp(1)
>   call-interactively(backward-sexp nil nil)
>   command-execute(backward-sexp)
>
> There are many more spots in this example to trigger error or
> unexpected moves.
>
> Or take this:
>
> ###
>
> if [ $# == 0 ]; then
>     # some comment (note: for compatibility)
>     set "" `find .  -maxdepth 1 -type f -name "*.txt" | sed
> s/..\(.*\)/\1/'`
>
>     for i in $*; do
>         # some comment (note: for compatibility)
>     pass
>     done
>
> fi
>
> ###
>
> With cursor at third line, "set", expression is not recognised at all,
> C-M-f stops at the end of symbol "set"
>
> That's a fakir's mode :)

There are hooks to customize those general commands to specific modes!
For example, instead of writing:

    bash-forward-sexp
    sh-forward-sexp
    pascal-forward-sexp
    ada-forward-sexp

etc, each mode will just bind a specific forward sexp function to the
hook variable:  forward-sexp-function, and forward-sexp will call it.


-- 
__Pascal Bourguignon__                 http://www.informatimago.com/
“The factory of the future will have only two employees, a man and a
dog. The man will be there to feed the dog. The dog will be there to
keep the man from touching the equipment.” -- Carl Bass CEO Autodesk


reply via email to

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