aboutsummaryrefslogtreecommitdiff
path: root/text.c
AgeCommit message (Collapse)AuthorFilesLines
2016-11-10vis-lua: change misnamed attribute values of `file.newlines`Marc André Tanner1-5/+5
Also rename underlying C code.
2016-11-01text: change usage of sizeof idiom for allocation of new objectsMarc André Tanner1-6/+6
The new code is preferable because it works independently of the variable type. Whereas before a change in type, but not within the sizeof expression would cause a wrongly sized allocation.
2016-11-01text: rename Buffer to Block to avoid confusion with buffer.[ch]Marc André Tanner1-123/+123
2016-09-25text: improve variable namingMarc André Tanner1-116/+116
s/Action/Revision/g
2016-05-07text: fix bug in line break caching logicMarc André Tanner1-1/+2
2016-04-18text: when saving also fsync(2) the destination directory after rename(2)Marc André Tanner1-1/+17
2016-04-17text: add infrastructure to save non-contiguous rangesMarc André Tanner1-113/+184
2016-03-23Remove identically replicated copyright comments from source filesMarc André Tanner1-15/+0
2016-03-15text: improve ENOSPC handling when savingMarc André Tanner1-0/+3
The default atomic save method using rename(2) would correctly fail, but the calling code would wrongly assume it was because of dealing with a special (e.g. hard or symlink) file or that some other properties (e.g. POSIX ACL, SELinux labels, permissions etc) could not be restored. It would then go on to ftruncate(2) the file, if the following writes then fail (which is likely if the new file content is bigger or some other process has used up disk space in the mean time) we lose data. This should fix it for the common case i.e. regular file where the rename(2) based method is used. The problem persits when directly overwriting a file. It is unclear whether this could be improved/fixed by: 1) first appending the new file content to the old one 2) fsync the data (old||new) 3) deleteing the original file content by overwritting it with the previously appended new file content. That is essentially moving the new file content from the end of the file to the start. 4) ftruncate to the new file size 5) fsync the data (new) if during 1) or 2) an error would occur we could revert the operation by doing a ftruncate to the original file size. An error in steps 3-5 would still be fatal. Another option would be to first write a backup file somewhere.
2016-02-21Cleanup new line insertion codeMarc André Tanner1-9/+12
2016-01-10text: introduce text_bytes_alloc0 utility functionMarc André Tanner1-0/+12
Heap allocates a zero terminated string of the given range. Freeing is the caller's responsibility. Checks for unsigned integer overflow i.e. passing SIZE_MAX as len will always fail because there is no room for the terminating NUL byte. This is important as EPOS is defined to be SIZE_MAX.
2015-12-31text: let text_pos_by_lineno return EPOS if given a too large line numberMarc André Tanner1-1/+1
2015-12-31text: introduce text_newline_insertMarc André Tanner1-0/+11
2015-12-29Clean up build systemMarc André Tanner1-6/+6
2015-11-23text: introduce functions to iterate over graphemesMarc André Tanner1-2/+55
They currently consider any character for which wcwidth(3) return 0 as a combining character.
2015-11-20text: get modification time after replacing file content in placeMarc André Tanner1-0/+2
At the start of text_save_range we stat(2) the file to check whether we have currently mmap(2)-ed it. Then we proceed to write the new file content which changes modification time. Hence we have to stat(2) again to retrieve it. This should fix spurious warnings about file changes outside the editor when editing e.g. symlinked files.
2015-11-08Update year numbers in Copyright clauseMarc André Tanner1-1/+1
2015-11-02text: return end of changed range in text_redoMarc André Tanner1-0/+2
This affects the cursor placement when redoing changes in single cursor mode. Closes #42
2015-10-22text: introduce text_appendf utility functionMarc André Tanner1-0/+8
2015-10-09text: fix usage of va_arg in text_vprintfDavid B. Lamkins1-1/+4
Closes #76
2015-10-05text: add text_{v,}printf functionMarc André Tanner1-0/+18
Convenient way to insert formated data into a Text.
2015-08-08text: rename some functions to improve consistencyMarc André Tanner1-7/+7
2015-08-08text: introduce helper function text_delete_rangeMarc André Tanner1-0/+6
2015-07-28text: move utility functions to separate fileMarc André Tanner1-36/+1
2015-07-25text: handle marks set to 0 and text_size(...)Marc André Tanner1-0/+8
2015-07-25text: add text_range_overlapMarc André Tanner1-0/+6
2015-07-22text: introduce text_range_newMarc André Tanner1-0/+7
2015-07-19vis: handle file truncation more gracefullyMarc André Tanner1-0/+8
If we use the file / virtual memory system as cache (using mmap(2)) and another process truncates the file we are editing, we have a problem. All we can do is catch the resulting SIGBUS, close the corresponding window and print a warning message. To test this use: $ dd if=/dev/zero of=TEST bs=8M count=1 $ vis TEST :! echo TRUNCATE > TEST
2015-07-19text: move regex related functions to separate fileMarc André Tanner1-68/+0
Eventually this should probably be rewritten to use an iternal regex engine, currently it has unacceptable memory usage, it copies the whole text.
2015-07-19text: slight cleanup, add a few commentsMarc André Tanner1-17/+22
2015-07-10text: upon successfull file save store new modification timeMarc André Tanner1-7/+11
2015-07-07text: safer temporary file creationMarc André Tanner1-1/+4
Set umask before calling mkstemp. According to POSIX 2008 this is not necessary since the temporary file is guaranteed to be created with permission restricted to the current user. However this is more secure on non-conforming systems and safe as long as we do not use multiple threads. Fixes Coverity CID 101333.
2015-07-07text: avoid double close in error caseMarc André Tanner1-0/+1
2015-07-07text: remove left over debugging codeMarc André Tanner1-6/+0
2015-07-06Warn when saving a file which has been changed outside the editorMarc André Tanner1-1/+8
2015-07-06text: remove text_load_fd and text_fd_getMarc André Tanner1-29/+10
2015-07-06Move filename from Text to FileMarc André Tanner1-14/+0
Also apply syntax rules every time the file name changes.
2015-07-06text: overhaul file load implementationMarc André Tanner1-3/+34
Files smaller than 8M are now copied into an internal buffer upon load. Thus they can be safely truncated. Larger files are memory mapped and use the file/virtual memory system as caching layer. Hence truncating them will corrupt the file content. Eventually the resulting SIGBUS should be handled gracefully.
2015-07-06text: overhaul save implemenationMarc André Tanner1-38/+193
Try to do an atomic save using rename(2) unless * the file is a symbolic link * the file is a hard link * file ownership can not be preserved * file group can not be preserved * POSXI ACL can not be preserved (if enabled) * SELinux security context can not be preserved (if enabled) in which case the file is overwritten in place. However a failure to do so results in data loss. Closes #47.
2015-07-05text: store buffer allocation type (mmap or malloc)Marc André Tanner1-16/+33
2015-07-03Do not take a snapshot in text_range_writeSilvan Jegen1-2/+0
Since text_range_write is called several times in cmd_filter, the undo command does not undo the whole filter operation but only up to the last call of text_range_write. Removing the snapshot-taking code solves this issue.
2015-07-03Remove text dump debugging codeMarc André Tanner1-16/+0
Instead use the text-dump git branch if necessary.
2015-06-28Fix copy/paste error in text_restoreMarc André Tanner1-1/+1
This really needs some unit tests.
2015-06-28Replace a->time with a->seq in history_traverse_toRyan Chipman1-3/+3
2015-06-28Add seq field to Action structRyan Chipman1-0/+8
2015-06-27Make :earlier and :later accept arguments similar to vimMarc André Tanner1-8/+30
Currently the following arguments are accepted: {count} Go to older text state {count} times. {N}s Go to older text state about {N} seconds before. {N}m Go to older text state about {N} minutes before. {N}h Go to older text state about {N} hours before. {N}d Go to older text state about {N} days before
2015-06-27Mark internal undo tree functions as staticMarc André Tanner1-4/+4
2015-06-27Core undo tree changesRyan Chipman1-50/+130
2015-06-24fixed some typos in commentsRyan Chipman1-2/+2
2015-04-22Cleanup line ending type detection and insertionMarc André Tanner1-7/+13