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: Andreas Röhler
Subject: Re: Defining functions on the fly
Date: Tue, 16 Jun 2015 12:26:43 +0200
User-agent: Mozilla/5.0 (X11; Linux i686; rv:31.0) Gecko/20100101 Thunderbird/31.4.0


Am 16.06.2015 um 11:50 schrieb Pascal J. Bourguignon:
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.



That's a consideration at the command- resp. key-binding level.
Nonetheless mode-specific functions are needed to bind then.

For now these language mode often invent very basic things in parallel: string-strip, in-string-p etc.
Also creating bugs and quirks that way.

Beyond that we can generalize top-level, block, expression and statement -- at least to some extend.



reply via email to

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