* [cperl-mode] cperl-indent-for-comment
@ 2010-05-05 19:42 LanX
2010-05-06 0:17 ` cperl-indent-for-comment LanX
` (2 more replies)
0 siblings, 3 replies; 9+ messages in thread
From: LanX @ 2010-05-05 19:42 UTC (permalink / raw)
To: help-gnu-emacs
Hi
Two questions;
1) I wanna make # more DWIM and automatically doing an indent-for-
comment when at the end of the line. I thought about
a) checking if the preceding character was a ";" or a paren.
and
b) checking with describe-text-property that I'm not within a string
or regex.
is b) the recommended way to do this?
2) cperl-indent-for-comment produces weird results when started within
a Perl-string (M-;), it indents but repeated calls produce a multiple
concatenated "# " at the end.
Is this the intended functionality???
Cheers
Rolf
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: cperl-indent-for-comment
2010-05-05 19:42 [cperl-mode] cperl-indent-for-comment LanX
@ 2010-05-06 0:17 ` LanX
2010-05-06 20:01 ` [cperl-mode] cperl-indent-for-comment Ilya Zakharevich
2010-05-07 2:35 ` [cperl-mode] cperl-indent-for-comment Stefan Monnier
2 siblings, 0 replies; 9+ messages in thread
From: LanX @ 2010-05-06 0:17 UTC (permalink / raw)
To: help-gnu-emacs
Hi
this is my first approach to question 1...
Any suggestions?
-----------------------------------------------------------
(defun dwim-indent-for-comment (arg)
"Indent comment after \; { ( [ otherwise insert #"
(interactive "p")
(if (and (memq (preceding-char) '( ?\; ?{ ?\( ?\[ ) )
(not (get-text-property (point) 'face))
)
(indent-for-comment)
(insert "#"))
)
(local-set-key (kbd "#") 'dwim-indent-for-comment)
-----------------------------------------------------------
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [cperl-mode] cperl-indent-for-comment
2010-05-05 19:42 [cperl-mode] cperl-indent-for-comment LanX
2010-05-06 0:17 ` cperl-indent-for-comment LanX
@ 2010-05-06 20:01 ` Ilya Zakharevich
2010-05-06 21:39 ` cperl-indent-for-comment LanX
2010-05-07 2:35 ` [cperl-mode] cperl-indent-for-comment Stefan Monnier
2 siblings, 1 reply; 9+ messages in thread
From: Ilya Zakharevich @ 2010-05-06 20:01 UTC (permalink / raw)
To: help-gnu-emacs
On 2010-05-05, LanX <lanx.perl@googlemail.com> wrote:
> 1) I wanna make # more DWIM and automatically doing an indent-for-
> comment when at the end of the line. I thought about
> a) checking if the preceding character was a ";" or a paren.
Why not do it more agressively, and just avoid it after $ ?
> and
> b) checking with describe-text-property that I'm not within a string
> or regex.
Keep in mind that one needs to force update of syntaxification before
checking text-properties.
(cperl-update-syntaxification (point) (point))
> 2) cperl-indent-for-comment produces weird results when started within
> a Perl-string (M-;), it indents but repeated calls produce a multiple
> concatenated "# " at the end.
Not in my version.
Yours,
Ilya
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: cperl-indent-for-comment
2010-05-06 20:01 ` [cperl-mode] cperl-indent-for-comment Ilya Zakharevich
@ 2010-05-06 21:39 ` LanX
2010-05-09 0:21 ` cperl-indent-for-comment Ilya Zakharevich
0 siblings, 1 reply; 9+ messages in thread
From: LanX @ 2010-05-06 21:39 UTC (permalink / raw)
To: help-gnu-emacs
Hi
> Why not do it more agressively, and just avoid it after $ ?
hmm ... technically I was worrying about #-delimiters like in
regexes ... but testing the face should already be sufficient.
I th this DWIM behavior should be restricted to the same end-of-line
scenarios like auto-newline.
If I need it explicitly from within the code I can use C-#.
But indeed thats a matter of taste and could be made customizable ...
> Keep in mind that one needs to force update of syntaxification before
> checking text-properties.
>
> (cperl-update-syntaxification (point) (point))
Good point 8)
-------------------------------------- Version 0.02
(defun my-indent-for-comment (arg)
"dwim indent-for-comment"
(interactive "p")
(cperl-update-syntaxification (point) (point))
(if (and (memq (preceding-char) '( ?\; ?{ ?\( ?\[ ) )
(not (get-text-property (point) 'face)))
(indent-for-comment)
(insert "#"))
)
(local-set-key (kbd "#") 'my-indent-for-comment)
----------------------------------------
TODO:
- checking for after code (whitespace till end of line)
- adding this case to cperl-electric-backspace
- handling the case of auto-newline.
> Not in my version.
your still running emacs 19 right?
For completeness:
putting the cursor right after the doublequote and pressing M-;
results in this
------------------------------------
$a=" # #
------------------------------------
every new try appends a new " #"
I started "emacs22 -q" and emacs23 and tested it with cperl "5.23 and
"6.2". (perl-mode is OK)
But this is not a really important bug...
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: cperl-indent-for-comment
2010-05-06 21:39 ` cperl-indent-for-comment LanX
@ 2010-05-09 0:21 ` Ilya Zakharevich
2010-05-10 12:58 ` cperl-indent-for-comment LanX
0 siblings, 1 reply; 9+ messages in thread
From: Ilya Zakharevich @ 2010-05-09 0:21 UTC (permalink / raw)
To: help-gnu-emacs
On 2010-05-06, LanX <lanx.perl@googlemail.com> wrote:
>> Not in my version.
> your still running emacs 19 right?
I have access to computers with v19, v20, and v21 around. I had to
one with v22, but it lost libpng (or somesuch) and Emacs won't load
anymore. Now let me recheck... AHA! That guy was updated, and now
has v23 - and it may actually be loaded!
Now I can start real testing...
> For completeness:
>
> putting the cursor right after the doublequote and pressing M-;
> results in this
> ------------------------------------
> $a=" # #
> ------------------------------------
>
> every new try appends a new " #"
>
> I started "emacs22 -q" and emacs23 and tested it with cperl "5.23 and
> "6.2". (perl-mode is OK)
>
> But this is not a really important bug...
For me it is. I get quite used to ALL my stuff working 100% of
time... (Or at least being quickly enough upgraded after problems are
discovered.) ( - Well, of course it is a pipe dream with scores of my
stuff on CPAN...)
Yours,
Ilya
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [cperl-mode] cperl-indent-for-comment
2010-05-05 19:42 [cperl-mode] cperl-indent-for-comment LanX
2010-05-06 0:17 ` cperl-indent-for-comment LanX
2010-05-06 20:01 ` [cperl-mode] cperl-indent-for-comment Ilya Zakharevich
@ 2010-05-07 2:35 ` Stefan Monnier
2 siblings, 0 replies; 9+ messages in thread
From: Stefan Monnier @ 2010-05-07 2:35 UTC (permalink / raw)
To: help-gnu-emacs
> b) checking with describe-text-property that I'm not within a string
> or regex.
You might want to try (nth 8 (syntax-ppss)) for that.
Stefan
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2010-05-14 16:08 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-05-05 19:42 [cperl-mode] cperl-indent-for-comment LanX
2010-05-06 0:17 ` cperl-indent-for-comment LanX
2010-05-06 20:01 ` [cperl-mode] cperl-indent-for-comment Ilya Zakharevich
2010-05-06 21:39 ` cperl-indent-for-comment LanX
2010-05-09 0:21 ` cperl-indent-for-comment Ilya Zakharevich
2010-05-10 12:58 ` cperl-indent-for-comment LanX
2010-05-10 23:56 ` cperl-indent-for-comment Ilya Zakharevich
2010-05-14 16:08 ` [cperl] electric-backspace and variable-refactoring LanX
2010-05-07 2:35 ` [cperl-mode] cperl-indent-for-comment Stefan Monnier
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.