I am using manual folding to write perl programs. Here is a typical fold:
sub do_something # does something --{{{
{
# perl code here
} # --}}}
When folded, these four lines are displayed thus:
+-- 4 lines: sub do_something does something ----------------------------
In the folded version, the hash mark before the word "does" has disappeared. Why? If this is a feature, how can I disable it? As a workaround, I am writing 'sub do_something ## does something --{{{', but is there a clean way to get vim to just display what I have typed? (Maybe this has something to do with perl.vim?)
What gets displayed instead of the folded lines is controlled by the 'foldtext' option. By default, the internal foldtext() function is used. :help foldtext() explains:
The returned string looks like this:
+-- 45 lines: abcdef
The number of dashes depends on the foldlevel. The "45" is
the number of lines in the fold. "abcdef" is the text in the
first non-blank line of the fold. Leading white space, "//"
or "/*" and the text from the 'foldmarker' and 'commentstring'
options is removed.
As you see, this is a heuristic of Vim to reduce clutter. To turn that off:
You can clear 'commentstring'; it is only used to add manual fold markers (and some commenting plugins may rely on it as a fallback), by putting :setlocal commentstring= into ~/.vim/after/ftplugin/perl.vim.
You can write your own fold function (example and instructions at :help fold-foldtext), and install that, either globally or (like above alternative) only for the Perl filetype.
Related
my code and the terminal .
file = "ex25.py", line 27
words=sort_sentence(sentence)
IndentationError: unindent does not match any other indentation level
The code I wrote in ex25 is:
def print_first_and_last_sorted(sentence):
words =sort_sentence(sentence)
print_first_word(words)
print_last_word(words)
After you define function with the first line, in the second line you need to use proper indentation or spaces. The standard is 4 spaces (4 space keystrokes) or 1 tab.
def print_first_and_last_sorted(sentence):
words =sort_sentence(sentence) # This line and next should be spaced 4 times with
print_first_word(words) # respect to the above one
print_last_word(words)
Your second line is not indented properly. You can compare it with the next lines. They all should be vertically parallel at their start points.
I can't comment but from both the edit and the original post, therefore I can't tell what the indentation actually is.
Python indentation works like blocks of code, similar to other languages except without the curly braces. For example:
def print_first_and_last_sorted(sentence):
words = sort_sentence(sentence)
print_first_word(words)
print_last_word(words)
You may have mixed up spaces & tabs. From this answer, try searching and replacing to replace them with a few spaces.
Here is my entire .vimrc:
set ignorecase
set scs
let perl_fold=1
hi Folded cterm=bold ctermfg=yellow ctermbg=lightblue
set modeline
set hidden
When loading a .pm file (which usually contains just a single package), all of the file's code is folded into a single line, and the first thing I have to do is to expand that fold.
Is there a way to have vim automatically expand that fold after loading the file? I em envisioning some sort of post-load hook which would allow me to say if the entire file (or more than 90%) is folded into a single line, then automatically expand that fold. (The "more than X %" condition might be needed if there are blank lines at the beginning of the file since they don't get folded.)
You could try (in your vimrc:
au BufReadPost *.pm normal zo
For reference: :help :autocmd, :help BufReadPost
For example I write code
if Foo do
# do something
end
And then, I paste in my code many lines.
if Foo do
# do something
# do something
# do something
# do something
# do something
end
How I can fast align added lines?
Do you want to align automatically on insert, or you want to align it later? For later you can use indent-region function (bound to C-M-\). For automatic align on insert you can use following recipe (I don't remember where I took it, so I'll refer to my config) - see lines 45-66. You will need to add more modes to yank-indent-modes, but concrete mode should provide working indent function.
I've been trying to make use of a cool feature of YASnippet: write snippets containing embedded Emacs Lisp code. There is a snippet for rst-mode that surrounds the entered text with "=" that is as long as the text such as in
====
Text
====
Based on this snippet, I decided to slightly modify it (with Elisp) so that it comments out these three lines depending on the major mode you are in (I thought that such a snippet would be useful to organize the source code). So I wrote this:
${1:`(insert comment-start)`} ${2:$(make-string (string-width text) ?\-)}
$1 ${2:Text}
$1 ${2:$(make-string (string-width text) ?\-)}
$0
This code works relatively well except for one problem: the indentation of these three lines gets mixed up, depending on the major mode I'm in (e.g., in emacs-lisp-mode, the second and the third lines move more to the right than the first line).
I think the source of the problem might have something to do with what comes after the string ${1: on the first line. If I add a character, I have no problem (i.e., all three lines are correctly aligned at the end of the snippet expansion). If I add a single space after this string, the misalignment problem still continues though.
So my question is: do you know of any way of rewriting this snippet so that this misalignment does not arise? Do you know what's the source of this behaviour?
Cheers,
From Writing snippets:
yas/indent-line
The variable yas/indent-line controls the indenting. It is bound to 'auto by default, which causes your snippet to be indented according to the mode of the buffer it was inserted in.
Another variable yas/also-auto-indent-first-line, when non-nil does exactly that :-).
To use the hard-coded indentation in your snippet template, set this variable to fixed.
To control indentation on a per-snippet basis, see also the directive # expand-env: in Writing Snippets.
For backward compatibility with earlier versions of YASnippet, you can also place a $> in your snippet, an (indent-according-to-mode) will be executed there to indent the line. This only takes effect when yas/indent-line is set to something other than 'auto.
for (${int i = 0}; ${i < 10}; ${++i})
{$>
$0$>
}$>
I'm writing an Emacs major mode for an APL dialect I use at work. I've gotten
basic font locking to work, and after setting comment-start and
comment-start-skip, comment/uncomment region and fill paragraph also
work.
However, comment blocks often contain javadoc style comments and i
would like fill-paragraph to avoid glueing together lines starting
with such commands.
If I have this (\ instead of javadoc #):
# This is a comment that is long and should be wrapped.
# \arg Description of argument
# \ret Description of return value
M-q gives me:
# This is a comment that is long and
# should be wrapped. \arg Description
# of argument \ret Description of
# return value
But I want:
# This is a comment that is long and
# should be wrapped.
# \arg Description of argument
# \ret Description of return value
I've tried setting up paragraph-start and paragraph-separate to
appropriate values, but fill-paragraph still doesn't work inside a
comment block. If I remove the comment markers, M-q works as I want
to, so the regexp I use for paragraph-start seems to work.
Do I have to write a custom fill-paragraph for my major
mode? cc-mode has one that handles cases like this, but it's really
complex, I'd like to avoid it if possible.
The problem was that the paragraph-start regexp has to match the entire line to work, including the actual comment character. The following elisp works for the example I gave:
(setq paragraph-start "^\\s-*\\#\\s-*\\\\\\(arg\\|ret\\).*$")
Here a page that has an example regexp for php-mode that does this:
http://barelyenough.org/blog/2006/10/nicer-phpdoc-comments/
There's other modes that have less complex functions used for fill-paragraph-function. Browsing through my install, it looks like the ones in ada-mode and make-mode are good examples.
What I do in these cases is open a blank line between the paragraph lines and the argument lines, then use M-q to wrap the paragraph lines, then kill the blank line between them. Not ideal, but it works and is easy enough to record in a macro if you need to repeat it.