all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Heuristics for: is a major-mode a "programming language" mode?
@ 2010-09-15  9:28 Ilya Zakharevich
  2010-09-15 13:12 ` Tim X
  2010-09-15 14:43 ` Xah Lee
  0 siblings, 2 replies; 10+ messages in thread
From: Ilya Zakharevich @ 2010-09-15  9:28 UTC (permalink / raw)
  To: help-gnu-emacs

I want a certain keypress act as forward-sexp in "programming
language" modes, and as forward-sentence (sp?) in other modes
(likewise for go-to-function-begin (sp?) and forward-paragraph (sp?)).

So there must be some code which decides "which type" is the given
major mode.  I would prefer the bulk of the decision to be made
programmatically, THEN let the user override if the auto-choice was
wrong.  Anyone with ideas how to do this?

Thanks,
Ilya

P.S.  In addition to sexp/sentence and function/paragraph, are there
      other "merges" one can do to do navigation?


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Heuristics for: is a major-mode a "programming language" mode?
  2010-09-15  9:28 Heuristics for: is a major-mode a "programming language" mode? Ilya Zakharevich
@ 2010-09-15 13:12 ` Tim X
  2010-09-15 14:27   ` Stefan Monnier
  2010-09-15 14:43 ` Xah Lee
  1 sibling, 1 reply; 10+ messages in thread
From: Tim X @ 2010-09-15 13:12 UTC (permalink / raw)
  To: help-gnu-emacs

Ilya Zakharevich <nospam-abuse@ilyaz.org> writes:

> I want a certain keypress act as forward-sexp in "programming
> language" modes, and as forward-sentence (sp?) in other modes
> (likewise for go-to-function-begin (sp?) and forward-paragraph (sp?)).
>
> So there must be some code which decides "which type" is the given
> major mode.  I would prefer the bulk of the decision to be made
> programmatically, THEN let the user override if the auto-choice was
> wrong.  Anyone with ideas how to do this?
>
> Thanks,
> Ilya
>
> P.S.  In addition to sexp/sentence and function/paragraph, are there
>       other "merges" one can do to do navigation?

Hi Ilya,

Not sure if this will help, but in current emacs 24, there is note in
the NEWS file about a new mode called prog-mode, which is supposed to be
a parent mode for programming modes. I believe the supplied prog modes
in emacs have/are being updated to be derived from this mode. 

The main role of this mode appears to be to run the hook prog-mode-hook.
Maybe this could be useful?

Tim

-- 
tcross (at) rapttech dot com dot au


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Heuristics for: is a major-mode a "programming language" mode?
  2010-09-15 13:12 ` Tim X
@ 2010-09-15 14:27   ` Stefan Monnier
  0 siblings, 0 replies; 10+ messages in thread
From: Stefan Monnier @ 2010-09-15 14:27 UTC (permalink / raw)
  To: help-gnu-emacs

> Not sure if this will help, but in current emacs 24, there is note in
> the NEWS file about a new mode called prog-mode, which is supposed to be
> a parent mode for programming modes. I believe the supplied prog modes
> in emacs have/are being updated to be derived from this mode. 

Indeed, this prog-mode should provide just the info that Ilya needs,
except that:
- it'll be new in Emacs-24.1, so it's not a good solution for "right now"
- only some of the major modes distributed with Emacs have been updated
  to use it, as of now.  Hopefully by 24.1 they will "all" have been
  adapted.
- non-bundled programming modes probably take a lot longer to start
  using it.

In the mean time, for modes bundled with Emacs, a good heuristic could
be to try and find the file from which the mode was loaded and then see
if that file is in "lisp/progmodes/" or elsewhere.  And of course that
will have some false positives (e.g. inferior-process interaction modes)
and false negatives (lisp-mode.el which i still in lisp/emacs-lisp).
And then come the ambiguous ones, like sgml-mode and latex-mode which
can be considered both as programming modes and text modes (they
currently inherit from text-mode only, tho).


        Stefan


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Heuristics for: is a major-mode a "programming language" mode?
  2010-09-15  9:28 Heuristics for: is a major-mode a "programming language" mode? Ilya Zakharevich
  2010-09-15 13:12 ` Tim X
@ 2010-09-15 14:43 ` Xah Lee
  2010-09-15 15:08   ` Stefan Monnier
  2010-09-16 23:40   ` Ilya Zakharevich
  1 sibling, 2 replies; 10+ messages in thread
From: Xah Lee @ 2010-09-15 14:43 UTC (permalink / raw)
  To: help-gnu-emacs

hi Ilya,

On Sep 15, 2:28 am, Ilya Zakharevich <nospam-ab...@ilyaz.org> wrote:
> I want a certain keypress act as forward-sexp in "programming
> language" modes, and as forward-sentence (sp?) in other modes
> (likewise for go-to-function-begin (sp?) and forward-paragraph (sp?)).
>
> So there must be some code which decides "which type" is the given
> major mode.  I would prefer the bulk of the decision to be made
> programmatically, THEN let the user override if the auto-choice was
> wrong.  Anyone with ideas how to do this?

a fool's answer: wouldn't just search for all the [] and {} heuristic
works pretty much?

most top 10 langs follow c-like syntax, so am guessing checking some
() {} would work out...

> P.S.  In addition to sexp/sentence and function/paragraph, are there
>       other "merges" one can do to do navigation?

i have similar need... i don't like forward/backward-paragraph in
programing mode. Their behavior is unpredictable. I instead defined
forward/backward-block, which is delimited by 2 empty lines. So, when
i use the key, i'm sure to land on the next/prev “block”.

there are 2 other thoughts similar to this... one is a desire to have
a formatting command that works for any lang. e.g. you press a button,
and the curren block, or region, or buffer, gets formatted, in any
lang, to a user set preference. No longer the pains to align code or
press tabs, per line. (there are tools for this in different lang...
usually called something-lint.)

• 〈A Simple Lisp Code Formatter〉
http://xahlee.org/emacs/lisp_formatter.html

... also, it's a fantasy of mine for C-h f to work in any lang. If
info file doc for the lang doesn't exist, just send user to web
browser of the lang's doc on that func. Wrote up more here
http://xahlee.org/emacs/emacs_lookup_ref.html

i guess the idea is than many nice things in emacs-lisp-mode can be
brought out to all langs, at least the top 10 major langs.

currently, i think each lang mode may implement some of this feature,
but the keybinding is different, behavior is different, degree of
support is different...

 Xah ∑ xahlee.org ☄


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Heuristics for: is a major-mode a "programming language" mode?
  2010-09-15 14:43 ` Xah Lee
@ 2010-09-15 15:08   ` Stefan Monnier
  2010-09-15 15:32     ` Xah Lee
  2010-09-16 23:43     ` Ilya Zakharevich
  2010-09-16 23:40   ` Ilya Zakharevich
  1 sibling, 2 replies; 10+ messages in thread
From: Stefan Monnier @ 2010-09-15 15:08 UTC (permalink / raw)
  To: help-gnu-emacs

>> So there must be some code which decides "which type" is the given
>> major mode.  I would prefer the bulk of the decision to be made
>> programmatically, THEN let the user override if the auto-choice was
>> wrong.  Anyone with ideas how to do this?

BTW, it occurred to me that maybe checking indent-line-function is
a good way to figure out whether the current mode is a programming mode.

> there are 2 other thoughts similar to this... one is a desire to have
> a formatting command that works for any lang. e.g. you press a button,
> and the curren block, or region, or buffer, gets formatted, in any
> lang, to a user set preference. No longer the pains to align code or
> press tabs, per line. (there are tools for this in different lang...
> usually called something-lint.)

In theory we already have 2 commands to do that:
- indent-region (C-M-\): works well in practice, but limited to
  re-indenting; i.e. it won't add/remove newlines.
- fill-region: in practice doesn't work at all.  In some major modes
  fill-paragraph will do what you want (or a variant of what you want,
  depending on your particular needs), but fill-region lacks hooks right
  now, so even the most careful major-mode writer won't be able to make
  it do the right thing.  There's a lot of room for improvement here.
  
> ... also, it's a fantasy of mine for C-h f to work in any lang. If
> info file doc for the lang doesn't exist, just send user to web
> browser of the lang's doc on that func.

The "info doc" part already exists: it's bound to C-h S.
It should be easy to make it able to use browse-url instead of Info.


        Stefan


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Heuristics for: is a major-mode a "programming language" mode?
  2010-09-15 15:08   ` Stefan Monnier
@ 2010-09-15 15:32     ` Xah Lee
  2010-09-15 23:22       ` Stefan Monnier
  2010-09-16 23:43     ` Ilya Zakharevich
  1 sibling, 1 reply; 10+ messages in thread
From: Xah Lee @ 2010-09-15 15:32 UTC (permalink / raw)
  To: help-gnu-emacs

On Sep 15, 8:08 am, Stefan Monnier <monn...@iro.umontreal.ca> wrote:
> >> So there must be some code which decides "which type" is the given
> >> major mode.  I would prefer the bulk of the decision to be made
> >> programmatically, THEN let the user override if the auto-choice was
> >> wrong.  Anyone with ideas how to do this?
>
> BTW, it occurred to me that maybe checking indent-line-function is
> a good way to figure out whether the current mode is a programming mode.
>
> > there are 2 other thoughts similar to this... one is a desire to have
> > a formatting command that works for any lang. e.g. you press a button,
> > and the curren block, or region, or buffer, gets formatted, in any
> > lang, to a user set preference. No longer the pains to align code or
> > press tabs, per line. (there are tools for this in different lang...
> > usually called something-lint.)
>
> In theory we already have 2 commands to do that:
> - indent-region (C-M-\): works well in practice, but limited to
>   re-indenting; i.e. it won't add/remove newlines.
> - fill-region: in practice doesn't work at all.  In some major modes
>   fill-paragraph will do what you want (or a variant of what you want,
>   depending on your particular needs), but fill-region lacks hooks right
>   now, so even the most careful major-mode writer won't be able to make
>   it do the right thing.  There's a lot of room for improvement here.

nice info. Yeah i use them... experience just as you described.

> > ... also, it's a fantasy of mine for C-h f to work in any lang. If
> > info file doc for the lang doesn't exist, just send user to web
> > browser of the lang's doc on that func.
>
> The "info doc" part already exists: it's bound to C-h S.
> It should be easy to make it able to use browse-url instead of Info.

haven't used this before. When i tried to do that in perl or python
mode, the mini-buffer seems to try to search the info doc but couldn't
find it....

am wondering to what extent it is currently being used in practice.
Does anyone reading here use this daily?

 Xah


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Heuristics for: is a major-mode a "programming language" mode?
  2010-09-15 15:32     ` Xah Lee
@ 2010-09-15 23:22       ` Stefan Monnier
  0 siblings, 0 replies; 10+ messages in thread
From: Stefan Monnier @ 2010-09-15 23:22 UTC (permalink / raw)
  To: help-gnu-emacs

>> The "info doc" part already exists: it's bound to C-h S.
>> It should be easy to make it able to use browse-url instead of Info.
> haven't used this before. When i tried to do that in perl or python
> mode, the mini-buffer seems to try to search the info doc but couldn't
> find it....
> am wondering to what extent it is currently being used in practice.
> Does anyone reading here use this daily?

I don't use it daily, but it's worked when I used it.
Of course, if you don't have the Info docs, it won't work (and that
failure mode may not be very clean), but otherwise it should.  If not,
please M-x report-emacs-bug.


        Stefan


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Heuristics for: is a major-mode a "programming language" mode?
  2010-09-15 14:43 ` Xah Lee
  2010-09-15 15:08   ` Stefan Monnier
@ 2010-09-16 23:40   ` Ilya Zakharevich
  1 sibling, 0 replies; 10+ messages in thread
From: Ilya Zakharevich @ 2010-09-16 23:40 UTC (permalink / raw)
  To: help-gnu-emacs

On 2010-09-15, Xah Lee <xahlee@gmail.com> wrote:
> On Sep 15, 2:28 am, Ilya Zakharevich <nospam-ab...@ilyaz.org> wrote:
>> I want a certain keypress act as forward-sexp in "programming
>> language" modes, and as forward-sentence (sp?) in other modes
>> (likewise for go-to-function-begin (sp?) and forward-paragraph (sp?)).
>>
>> So there must be some code which decides "which type" is the given
>> major mode.  I would prefer the bulk of the decision to be made
>> programmatically, THEN let the user override if the auto-choice was
>> wrong.  Anyone with ideas how to do this?
>
> a fool's answer: wouldn't just search for all the [] and {} heuristic
> works pretty much?
>
> most top 10 langs follow c-like syntax, so am guessing checking some
> () {} would work out...

I'm puzzled: "search for [] {}" WHERE?

Thanks,
Ilya


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Heuristics for: is a major-mode a "programming language" mode?
  2010-09-15 15:08   ` Stefan Monnier
  2010-09-15 15:32     ` Xah Lee
@ 2010-09-16 23:43     ` Ilya Zakharevich
  2010-09-17  9:50       ` Stefan Monnier
  1 sibling, 1 reply; 10+ messages in thread
From: Ilya Zakharevich @ 2010-09-16 23:43 UTC (permalink / raw)
  To: help-gnu-emacs

On 2010-09-15, Stefan Monnier <monnier@iro.umontreal.ca> wrote:
>>> So there must be some code which decides "which type" is the given
>>> major mode.  I would prefer the bulk of the decision to be made
>>> programmatically, THEN let the user override if the auto-choice was
>>> wrong.  Anyone with ideas how to do this?
>
> BTW, it occurred to me that maybe checking indent-line-function is
> a good way to figure out whether the current mode is a programming mode.

That's a cool idea!  Now I need to check emacs v19-24 and see what is/was
the default value for this.  ;-)

> In theory we already have 2 commands to do that:
> - indent-region (C-M-\): works well in practice, but limited to
>   re-indenting; i.e. it won't add/remove newlines.

It will.  At least in CPerl, if the user desires (configurable).

Thanks,
Ilya


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Heuristics for: is a major-mode a "programming language" mode?
  2010-09-16 23:43     ` Ilya Zakharevich
@ 2010-09-17  9:50       ` Stefan Monnier
  0 siblings, 0 replies; 10+ messages in thread
From: Stefan Monnier @ 2010-09-17  9:50 UTC (permalink / raw)
  To: help-gnu-emacs

>>>> So there must be some code which decides "which type" is the given
>>>> major mode.  I would prefer the bulk of the decision to be made
>>>> programmatically, THEN let the user override if the auto-choice was
>>>> wrong.  Anyone with ideas how to do this?
>> BTW, it occurred to me that maybe checking indent-line-function is
>> a good way to figure out whether the current mode is a programming mode.
> That's a cool idea!  Now I need to check emacs v19-24 and see what is/was
> the default value for this.  ;-)

I think that if you ignore indent-relative, indent-relative-maybe, and
indent-to-left-margin, (you can add (default-value
'indent-line-function) to the mix if you want) you'll catch the vast
majority of non-programming modes (at least under Emacs).

>> In theory we already have 2 commands to do that:
>> - indent-region (C-M-\): works well in practice, but limited to
>> re-indenting; i.e. it won't add/remove newlines.
> It will.  At least in CPerl, if the user desires (configurable).

Thanks for the precision,


        Stefan


^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2010-09-17  9:50 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-09-15  9:28 Heuristics for: is a major-mode a "programming language" mode? Ilya Zakharevich
2010-09-15 13:12 ` Tim X
2010-09-15 14:27   ` Stefan Monnier
2010-09-15 14:43 ` Xah Lee
2010-09-15 15:08   ` Stefan Monnier
2010-09-15 15:32     ` Xah Lee
2010-09-15 23:22       ` Stefan Monnier
2010-09-16 23:43     ` Ilya Zakharevich
2010-09-17  9:50       ` Stefan Monnier
2010-09-16 23:40   ` Ilya Zakharevich

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.