When I assign a new command and call it at the beginning of a \par the space between the variable text and next word is missing.
\newcommand{\testcmd}{This is a test}
\par \testcmd foobar.
Will be rendered as:
This is a testfoobar.
\par foo \testcmd bar.
Renders fine as: foo This is a test bar.
Anyone come across this before and have a solution?
Thanks
I do not know the exact thing which is going on here but there are several ways to get that space back:
\newcommand{\testcmd}{This is a test } % <- space before closing brace
par \testcmd{} foobar % <- note {}
The most verbose but the most robust way too:
\usepackage{xspace}
\newcommand{\testcmd}{This is a test\xspace}
Actually a much simpler answer would be to:
\newcommand{\testcmd}{This is a test}
\par \testcmd \ foobar.
Notice the extra "\ " before foobar (slash and space). No extra package needed. It is the same as the most common method for things like:
Mr.\ Smith
etc.\ and
Proc.\ Amer.\ Math.\ Soc.
Related
When writing new functions with Vim I always seem to have to do a bit of "manual" work.
x = Cursor position
If I start typing a function and insert a couple of curly braces and the end
function Apples() {x}
Then hit Enter, it obviously looks like this
function Apples() {
x}
Which results in me having to ESC,O in order to shift the closing curlybrace down.
While this may seem like a trivial matter, doing this over the last 5 months is getting bothersome, and I know there are plenty like me out there who knows there should be an elegant solution to this. I am open to plugin-suggestions.
You can use a simple mapping like this one (there are dozens of variants floating around SO and the web):
inoremap {} {<CR>}<C-o>O
You can also search www.vim.org for a dedicated plugin.
But I strongly recommend you to try a snippet-expansion plugin like Snipmate or UltiSnips. Both plugins follow the same model but they have slightly different snippet syntaxes and features. It works like that:
you type a trigger:
fun
you hit <Tab> and you get the following with function_name in select mode:
function [function_name]() {
}
you type your desired name:
function Apples|() {
}
you hit <Tab> to place the cursor between the parentheses:
function Apples(|) {
}
you hit <Tab> again to place the cursor on the line below with the correct indentation:
function Apples() {
|
}
With lh-bracket (in C or C++ mode), when you hit enter whilst in between two brackets, the newlines you are expecting are inserted.
The idea is to test for: getline(".")[col(".")-2:col(".")-1]=="{}" and execute/insert "\<cr>\<esc>O" when the condition is true, or "\<cr>" otherwise.
Within lh-bracket, I have the following into a C-ftplugin:
call lh#brackets#enrich_imap('<cr>',
\ {'condition': 'getline(".")[col(".")-2:col(".")-1]=="{}"',
\ 'action': 'Cpp_Add2NewLinesBetweenBrackets()'},
\ 1,
\ '\<cr\>'
\ )
function! Cpp_Add2NewLinesBetweenBrackets()
return "\<cr>\<esc>O"
endfunction
I guess (code not tested) it would (*) translate into:
" put it into ftplugin/{yourfiltetype, javascript?}.vim
inoremap <buffer> <silent> <expr> <cr> s:SmartCR()
function s:SmartCR()
return getline(".")[col(".")-2:col(".")-1]=="{}"
\ ? "\<cr>\<esc>O"
\ : "\<cr>"
endfunction
(*) Actually, lh#brackets#enrich_imap does a few other things (the mapping is compatible with LaTeXSuite's IMAP.vim presence ; the mapping can be toggled on/off along with all the other mappings from lh-brackets)
We use .NET here at work and our project is a little mixed, with some VB and C#. Exuberant Ctags generates C# tags just fine for me following these instructions. However, I have yet to be able to figure out how to get it to generate tags for my VB.NET code. The only article I've found that was somewhat helpful is this one. But at 2003 it ranks just a few years old. The first thing I noticed is that this line:
--langmap=vb:.bas.cls.ctl.frm.vbs
Is wrong, and also old. I changed it to read:
--langmap=vb:.vb
That improved my results slightly, but it still doesn't seem to generate the expected behavior (e.g. when I :set tag=tags and do ^] or g] on a function call or parameter, it has no tags).
This is what my ctags.cnf file looks like (and I have verified that it's being used):
--langdef=vb
--langmap=vb:.vb
--regex-vb=/^(Public|Private|\b)[ \t]*Sub[ \t]+([a-zA-Z0-9_]+)/\2/s,subroutine/i
--regex-vb=/^(Public|Private|\b)[ \t]*Function[ \t]+([a-zA-Z0-9_]+)/\2/f,function/i
--regex-vb=/^(Public|Private)[ \t]+([a-zA-Z0-9_]+)[ \t]+As[ \t]+/\2/v,variable/i
--regex-vb=/^(Public|Private|\b)[ \t]*Const[ \t]+([a-zA-Z0-9_]+)[ \t]+(As|=)[ \t]+/\2/c,const/i
--regex-vb=/^(Public|\b)[ \t]*Property[ \t]*(Get|Let|Set)[ \t]+([a-zA-Z0-9_]+)/\3/n,name/i
--regex-vb=/^(Public|Private|\b)[ \t]*Enum[ \t]+([a-zA-Z0-9_]+)/\2/e,enum/i
--regex-vb=/^([a-zA-Z_]+):/\1/l,label/i
--recurse
--exclude="bin"
--exclude="obj"
--fields=+ianmzS
--extra=+fq
--vb-kinds=cn
Any clue what I need to do to get proper support?
Edit:
This is a snip from my tag file:
!_TAG_FILE_FORMAT 2 /extended format; --format=1 will not append ;" to lines/
!_TAG_FILE_SORTED 1 /0=unsorted, 1=sorted, 2=foldcase/
!_TAG_PROGRAM_AUTHOR Darren Hiebert /dhiebert#users.sourceforge.net/
!_TAG_PROGRAM_NAME Exuberant Ctags //
!_TAG_PROGRAM_URL http://ctags.sourceforge.net /official site/
!_TAG_PROGRAM_VERSION 5.8 //
Application.Designer.vb .\My Project\Application.Designer.vb 1;" kind:F line:1
Application.Designer.vb .\Nuts\My Project\Application.Designer.vb 1;" kind:F line:1
AssemblyInfo.vb .\My Project\AssemblyInfo.vb 1;" kind:F line:1
AssemblyInfo.vb .\Nuts\My Project\AssemblyInfo.vb 1;" kind:F line:1
AttachmentHandler.vb .\Utilities\AttachmentHandler.vb 1;" kind:F line:1
While my CS codebase generates tags like this:
SomeModel .\Client\Views\Models\Namespace\SomeModel.cs /^ public class SomeModel$/;" kind:c line:12 namespace:Views.Models.SomeModel access:public
Unless you follow a zero-indent coding convention your regular expressions won't work ;)
Try:
// Note the extra [ \t]* right after ^
--regex-vb=/^[ \t]*(Public|Private|\b)[ \t]*Sub[ \t]+([a-zA-Z0-9_]+)/\2/s,subroutine/i
Here is a working configuration, extracted from my ~/.ctags, based on that from OP's and applying accepted answer edit.
I had to remove the label matcher as this prevented all Sub/Function matches (not sure why) and replace the (Public|Private|\b) with (Public|Private)? to get it to optionally match access modifiers (else it didn't match any without these modifiers for me).
--exclude="bin"
--exclude="obj"
--langdef=vb
--langmap=vb:.vb
--regex-vb=/^[ \t]*(Public|Private)?[ \t]*Sub[ \t]+([a-zA-Z0-9_]+)/\2/s,subroutine/i
--regex-vb=/^[ \t]*(Public|Private)?[ \t]*Function[ \t]+([a-zA-Z0-9_]+)/\2/f,function/i
--regex-vb=/^[ \t]*(Public|Private)[ \t]+([a-zA-Z0-9_]+)[ \t]+As[ \t]+/\2/v,variable/i
--regex-vb=/^[ \t]*(Public|Private)?[ \t]*Const[ \t]+([a-zA-Z0-9_]+)[ \t]+(As|=)[ \t]+/\2/c,const/i
--regex-vb=/^[ \t]*(Public)?[ \t]*Property[ \t]*(Get|Let|Set)[ \t]+([a-zA-Z0-9_]+)/\3/n,name/i
--regex-vb=/^[ \t]*(Public|Private)?[ \t]*Enum[ \t]+([a-zA-Z0-9_]+)/\2/e,enum/i
#--regex-vb=/^[ \t]*([a-zA-Z_]+):/\1/l,label/i
--recurse
--fields=+ianmzS
--extra=+fq
--vb-kinds=cn
I'm using
while( (getline line < "filename") > 0 )
within my BEGIN statement, but this while loop only seems to read the last line of the file instead of each line. I think it may be a newline character problem, but really I don't know. Any ideas?
I'm trying to read the data in from a file other than the main input file.
The same syntax actually works for one file, but not another, and the only difference I see is that the one for which it DOES work has "^M" at the end of each line when I look at it in Vim, and the one for which it DOESN'T work doesn't have ^M. But this seems like an odd problem to be having on my (UNIX based) Mac.
I wish I understood what was going with getline a lot better than I do.
You would have to specify RS to something more vague.
Here is a ugly hack to get things working
RS="[\x0d\x0a\x0d]"
Now, this may require some explanation.
Diffrent systems use difrent ways to handle change of line.
Read http://en.wikipedia.org/wiki/Carriage_return and http://en.wikipedia.org/wiki/Newline if you are
interested in it.
Normally awk hadles this gracefully, but it appears that in your enviroment, some files are being naughty.
0x0d or 0x0a or 0x0d 0x0a (CR+LF) should be there, but not mixed.
So lets try a example of a mixed data stream
$ echo -e "foo\x0d\x0abar\x0d\x0adoe\x0arar\x0azoe\x0dqwe\x0dtry" |awk 'BEGIN{while((getline r )>0){print "r=["r"]";}}'
Result:
r=[foo]
r=[bar]
r=[doe]
r=[rar]
try]oe
We can see that the last lines are lost.
Now using the ugly hack to RS
$ echo -e "foo\x0d\x0abar\x0d\x0adoe\x0arar\x0azoe\x0dqwe\x0dtry" |awk 'BEGIN{RS="[\x0d\x0a\x0d]";while((getline r )>0){print "r=["r"]";}}'
Result:
r=[foo]
r=[bar]
r=[doe]
r=[rar]
r=[zoe]
r=[qwe]
r=[try]
We can see every line is obtained, reguardless of the 0x0d 0x0a junk :-)
Maybe you should preprocess your input file with for example dos2unix (http://sourceforge.net/projects/dos2unix/) utility?
I cannot compile an extremely simple ocaml program test2.ml
open Test1
print_string " Hello "
with test1.ml containing only 1 line
type program = string
And test1.ml is compiled:
bash-3.2$ ocamlc test1.ml
bash-3.2$ ls test1.*
test1.cmi test1.cmo test1.ml
Anyone know why test1.ml does not compile?? Thank you.
More info. It's quite strange because, test2.ml compiles if I comment out its first line "open ..." OR
if I comment out its 3rd line "print_string..." but they cannot coexist!
Printing the error you received would have been helpful. For the reference, it's:
File "test2.ml", line 3, characters 0-12:
Error: Syntax error
The reason for this is a bit complex. The normal syntax is for a file to be a sequence of top-level statements, such as type definitions, let (without in), module definition/opening/including and so on.
Expressions such as print_string "Hello" are never treated as top-level statements unless the meaning is completely unambiguous, which 99% of the time involves separating them from the previous and following statement with a ;;
So, you could write the following:
open Test1 ;;
print_string " Hello "
And it would work. Most of the time, though, it is preferable to keep the file clean by turning the expression into a top-level let:
open Test1
let () = print_string " Hello "
This also has the benefit of making sure that the function returns unit, which is always nice to have.
As a first project I have been writing a short program to render the Mandelbrot fractal. I have got to the point of trying to output my results to a file ( e.g. .bmp or .ppm ) and got stuck.
I have not really found any examples of exactly what I am trying to do, but I have found two examples of code to copy from one file to another.
The examples in the Gforth documentation ( Section 3.27 ) did not work for me ( winXP ) in fact they seemed to open and create files but not write to files properly.
This is the Gforth documentation example that copies the contents of one file to another:
0 Value fd-in
0 Value fd-out
: open-input ( addr u -- ) r/o open-file throw to fd-in ;
: open-output ( addr u -- ) w/o create-file throw to fd-out ;
s" foo.in" open-input
s" foo.out" open-output
: copy-file ( -- )
begin
line-buffer max-line fd-in read-line throw
while
line-buffer swap fd-out write-line throw
repeat ;
I found this example ( http://rosettacode.org/wiki/File_IO#Forth ) which does work. The main problem is that I can't isolate the part that writes to a file and have it still work. The main confusion is that >r doesn't seem to consume TOS as I might expect.
: copy-file2 ( a1 n1 a2 n2 -- )
r/o open-file throw >r
w/o create-file throw r>
begin
pad maxstring 2 pick read-file throw
?dup while
pad swap 3 pick write-file throw
repeat
close-file throw
close-file throw ;
\ Invoke it like this:
s" output.txt" s" input.txt" copy-file
I would be very grateful if someone could explain exactly how the open, create read and write -file words actually work, as my investigation keeps resulting in somewhat bizarre stacks.
Any clues as to why the Gforth examples do not work might help too.
In summary, I want to output from Gforth to a file and so far have been thwarted. Can anyone offer any help?
Thank you Vijay, I think that I understand the example that you gave. However when I try to use something like this ( which I think is similar ):
0 value test-file
: write-test
s" testfile.out" w/o create-file throw to test-file
s" test text" test-file write-line ;
I get ok but nothing is put into the file, have I made a mistake?
It seems that the problem was due to not flushing the relevant buffers or explicitly closing the file. Adding something like
test-file flush-file throw
or
test-file close-file throw
between write-line and ; makes it work. Consequently the Gforth documentation example would have worked had I followed the instructions.
Thanks again Vijay for helping.
I will try to explain how write-line works with this simple example. Here we have a buffer that contains the string " hello", and we want to write that to a file opened with open-output.
buffer 5 fd-out write-line
5 is the length of the buffer. fd-out is the open file handle. A call to write-line will leave an integer result on the stack, the value of which is implementation dependent. More information on the file I/O words could be found in File Access words.
Calling the word throw is optional. It will check the integer value on the top of the stack and based on that value either pops the topmost exception frame from the exception stack or call abort or display an implementation-dependent message giving information about the condition associated with the integer. (Exact details on how throw works could be found in THROW).
You program is incomplete, which makes the question hard to answer.
With prepending
1024 CONSTANT max-line
CREATE line-buffer max-line 3 + ALLOT
and postpending
copy-file
fd-in close-file throw
fd-out close-file throw
and after creating a testfile foo.in gforth the first program works flawlessly on Debian.
Probably your problem is caused by not properly closing the file after writing.