About: Preserve missing end-of-line at end of text files   Sponge Permalink

An Entity of Type : owl:Thing, within Data Space : 134.155.108.49:8890 associated with source dataset(s)

This works for all three line ending styles which Vim recognizes: DOS (Windows), Unix, and traditional Mac. The script relies on Vim's recognition of a missing line ending, saved in the 'eol' option value. Even though 'eol' is set properly, it only has any effects when 'binary' is also set. So, the core of the script simply sets 'binary' temporarily. Unfortunately, when 'binary' is set, the file is always written with Unix-format line endings. So the rest of the script manually adds the correct line endings for the current format, and removes them again after writing. augroup automatic_noeol

AttributesValues
rdfs:label
  • Preserve missing end-of-line at end of text files
rdfs:comment
  • This works for all three line ending styles which Vim recognizes: DOS (Windows), Unix, and traditional Mac. The script relies on Vim's recognition of a missing line ending, saved in the 'eol' option value. Even though 'eol' is set properly, it only has any effects when 'binary' is also set. So, the core of the script simply sets 'binary' temporarily. Unfortunately, when 'binary' is set, the file is always written with Unix-format line endings. So the rest of the script manually adds the correct line endings for the current format, and removes them again after writing. augroup automatic_noeol
Version
  • 6(xsd:integer)
dbkwik:vim/property/wikiPageUsesTemplate
Previous
  • 1366(xsd:integer)
Category
  • Fileformat
Text
  • PreserveNoEOL plugin
Author
  • Yakov Lerner
Complexity
  • basic
Created
  • 2006(xsd:integer)
ID
  • 1369(xsd:integer)
  • 4550(xsd:integer)
NEXT
  • 1370(xsd:integer)
Rating
  • 0(xsd:integer)
abstract
  • This works for all three line ending styles which Vim recognizes: DOS (Windows), Unix, and traditional Mac. The script relies on Vim's recognition of a missing line ending, saved in the 'eol' option value. Even though 'eol' is set properly, it only has any effects when 'binary' is also set. So, the core of the script simply sets 'binary' temporarily. Unfortunately, when 'binary' is set, the file is always written with Unix-format line endings. So the rest of the script manually adds the correct line endings for the current format, and removes them again after writing. :undojoin is used to keep these temporary line ending transformations transparent to the user. " Preserve noeol (missing trailing eol) when saving file. In order " to do this we need to temporarily 'set binary' for the duration of " file writing, and for DOS line endings, add the CRs manually. " For Mac line endings, also must join everything to one line since it doesn't " use a LF character anywhere and 'binary' writes everything as if it were Unix. " This works because 'eol' is set properly no matter what file format is used, " even if it is only used when 'binary' is set. augroup automatic_noeol au! au BufWritePre * call TempSetBinaryForNoeol() au BufWritePost * call TempRestoreBinaryForNoeol() augroup END function! s:TempSetBinaryForNoeol() let s:save_binary = &binary if ! &eol && ! &binary let s:save_view = winsaveview() setlocal binary if &ff == "dos" || &ff == "mac" if line('$') > 1 undojoin | exec "silent 1,$-1normal! A\\" endif endif if &ff == "mac" undojoin | %join! " mac format does not use a anywhere, so we don't add one when writing " in binary (which uses unix format always). However, inside the outer " if statement, we already know that 'noeol' is set, so no special logic " is needed. endif endif endfunction function! s:TempRestoreBinaryForNoeol() if ! &eol && ! s:save_binary if &ff == "dos" if line('$') > 1 " Sometimes undojoin gives errors here, even when it shouldn't. " Suppress them for now...if you can figure out and fix them instead, " please update silent! undojoin | silent 1,$-1s/$//e endif elseif &ff == "mac" " Sometimes undojoin gives errors here, even when it shouldn't. " Suppress them for now...if you can figure out and fix them instead, " please update silent! undojoin | silent %s///ge endif setlocal nobinary call winrestview(s:save_view) endif endfunction
Alternative Linked Data Views: ODE     Raw Data in: CXML | CSV | RDF ( N-Triples N3/Turtle JSON XML ) | OData ( Atom JSON ) | Microdata ( JSON HTML) | JSON-LD    About   
This material is Open Knowledge   W3C Semantic Web Technology [RDF Data] Valid XHTML + RDFa
OpenLink Virtuoso version 07.20.3217, on Linux (x86_64-pc-linux-gnu), Standard Edition
Data on this page belongs to its respective rights holders.
Virtuoso Faceted Browser Copyright © 2009-2012 OpenLink Software