It does not seem to be possible to "comment out" blocks of code, which would
be a very nice feature for testing purposes. (Maybe I can do it with """
but that looks a bit cumbersome.)
Any ideas, hint, proposals?
--
Js Bi
"Il n'y a guère dans la vie qu'une préoccupation grave: c'est la mort;"
(Dumas)
-----------== Posted via Newsgroups.Com - Uncensored Usenet News ==----------
http://www.newsgroups.com The #1 Newsgroup Service in the World!
-----= Over 100,000 Newsgroups - Ulimited Fast Downloads - 19 Servers =-----
> This question was probably asked many times.
>
> It does not seem to be possible to "comment out" blocks of code, which would
> be a very nice feature for testing purposes. (Maybe I can do it with """
> but that looks a bit cumbersome.)
>
> Any ideas, hint, proposals?
The typical solution is to put the entire block in a "if 0:"
statement. If your editor does not conveniently allow to right-indent
a block of code, you may succeed with putting the if statement on the
half indentation level; you'll need to add 'if 1:' for the rest of the
block in this case, also.
HTH,
Martin
""" and 'if 0:' are the standard possibilities. I guess one would
need a truly developer oriented IDE to implement this indepently from
language (handling say a all-included-file and a work-file separetely).
Can't emacs or vi do folding/collapsing several lines into one line
and allow writing out non-folded lines only?
> --jb
jb answers jb. maybe i am joining a monologue?
:-),
holger
> This question was probably asked many times.
>
> It does not seem to be possible to "comment out" blocks of code, which would
> be a very nice feature for testing purposes. (Maybe I can do it with """
> but that looks a bit cumbersome.)
>
> Any ideas, hint, proposals?
Prefix your code segment with
if 0:
and indent it a level.
This is not as fully general as #ifdef but since even declarations are executed
at runtime, it'll serve as a way to selectively include or exclude blocks of
code.
Regards
--jb
--
James J. Besemer 503-280-0838 voice
http://cascade-sys.com 503-280-0375 fax
mailto:j...@cascade-sys.com
> Prefix your code segment with
>
> if 0:
>
> and indent it a level.
>
> This is not as fully general as #ifdef but since even declarations are
> executed at runtime, it'll serve as a way to selectively include or exclude
> blocks of code.
>
Why not just use #ifdef? ;) I'm only half joking: it would take a few minutes
to whip up a shell script to run your python code through the gcc
preprocessor first before passing it to python. As long as you have spaces in
your normal comments (no #include as a comment), you should be allright, no?
I haven't actually tried it, so maybe the preprocessor would somehow get
confused, and yes, it's a bit of a twisted idea. But fun ;)
cheers,
f.
Typing \n''' twice is hardly any more cumbersome than typing \n/*,
\n*/.
The ease of repeats compesates for the two extra keystrokes.
Terry J. Reedy
[...]
C-c # to comment, C-c rk to uncomment (kill rectangle, to be specific), in
emacs.
John
Need to scan for ''' in the "commented-out" part though.
Regards,
Bengt Richter
thanks. but this doesn't do 'collapsing' several lines into temporary
nothingness.
holger
Sorry, was really replying to the thread in general rather than your
specific Q.; but I think emacs' does have a minor mode to do this (can't
remember what it's called, so this may be disinformation: could be a major
mode, in which case you can't mix it w/ python-mode of course).
John
I missed the start of this, but, is this what you want? Courtesy
Ronny Wikh rw @ strakt.com
This we use to make whole classes go away so you can see program structure.
Laura
---------
;;
;; python outline mode
;;
(defvar outline-start-hidden t "Start outline hidden")
(defun outline-setup (regexp)
"Setup outline mode"
(defvar outline-toggle-all-flag nil "toggle all flag")
(defvar cpos_save nil "current cursor position")
(outline-minor-mode)
(setq outline-regexp regexp)
(define-key outline-minor-mode-map "\C-c\C-e" 'outline-toggle-entry)
(define-key outline-minor-mode-map "\C-c\C-a" 'outline-toggle-all)
(if outline-start-hidden
(hide-body))
(defun outline-toggle-entry () (interactive)
"Toggle outline hiding for the entry under the cursor"
(if (progn
(setq cpos_save (point))
(end-of-line)
(get-char-property (point) 'invisible))
(progn
(show-subtree)
(goto-char cpos_save))
(progn
(hide-leaves)
(goto-char cpos_save))))
(defun outline-toggle-all () (interactive)
"Toggle outline hiding for the entire file"
(if outline-toggle-all-flag
(progn
(setq outline-toggle-all-flag nil)
(hide-body))
(progn
(setq outline-toggle-all-flag t)
(show-all))))
)
(defun python-outline () (interactive)
"Python outline mode"
(python-mode)
(outline-setup "^class \\|[ ]*def \\|^#"))
(defun texi-outline () (interactive)
"Texinfo outline mode"
(texinfo-mode)
(outline-setup "^@chap\\|@\\(sub\\)*section"))
One thing I love in UserTalk (of Frontier, Manilla and Radio UserLand
fame) is the 'bundle' keyword that simply provides another variable
scope and bundles up a few lines of code.
In the Frontier/Radio environment all programming is done in an
outliner, and bundling turns out to be a whole lot nicer than it
originally looks -- so much so, that these days I curse as much about
there being no 'bundle' in Python as I do about most Python features
lacking in UserTalk. :)
Compare::
# do this
... code to do this
# do that
... code to do that
With::
bundle # do this
... code to do this
bundle # do that
... code to do that
I'm almost tested to hack it:
if 1: # do this
... code to do this
... but that's a little ghastly. If I could figure out a way to add a
keyword in pure Python, I'd do it. :)
Regards,
Garth.
cpp will choke on strings spanning multiple lines; it knows too much
about C syntax. You could use m4.
My usual way to comment out a block is to highlight it and type
control-C #, which comments out the block. But I use Emacs.
I fail to see any advantage to that structure. Wouldn't this be
even better in any case? :
subroutineCallToDoThis()
subroutineCallToDoThat()
It's more concise, self-documenting, more modular, maintainable,
more testable, and so forth....
Just what value does "bundle" provide? Your example doesn't show it.
-Peter