Mercurial > vim
comparison src/fileio.c @ 5231:74d2f3188cd0 v7.4a.041
updated for version 7.4a.041
Problem: When using ":new ++ff=unix" and "dos" is first in 'fileformats'
then 'ff' is set to "dos" instead of "unix". (Ingo Karkat)
Solution: Create set_file_options() and invoke it from do_ecmd().
author | Bram Moolenaar <bram@vim.org> |
---|---|
date | Wed, 24 Jul 2013 15:02:03 +0200 |
parents | 93cccad6a26b |
children | 6b7ab6a4f31a |
comparison
equal
deleted
inserted
replaced
5230:a25b52f7f08e | 5231:74d2f3188cd0 |
---|---|
472 } | 472 } |
473 # endif | 473 # endif |
474 } | 474 } |
475 #endif | 475 #endif |
476 | 476 |
477 /* set default 'fileformat' */ | 477 /* Set default or forced 'fileformat' and 'binary'. */ |
478 if (set_options) | 478 set_file_options(set_options, eap); |
479 { | |
480 if (eap != NULL && eap->force_ff != 0) | |
481 set_fileformat(get_fileformat_force(curbuf, eap), OPT_LOCAL); | |
482 else if (*p_ffs != NUL) | |
483 set_fileformat(default_fileformat(), OPT_LOCAL); | |
484 } | |
485 | |
486 /* set or reset 'binary' */ | |
487 if (eap != NULL && eap->force_bin != 0) | |
488 { | |
489 int oldval = curbuf->b_p_bin; | |
490 | |
491 curbuf->b_p_bin = (eap->force_bin == FORCE_BIN); | |
492 set_options_bin(oldval, curbuf->b_p_bin, OPT_LOCAL); | |
493 } | |
494 | 479 |
495 /* | 480 /* |
496 * When opening a new file we take the readonly flag from the file. | 481 * When opening a new file we take the readonly flag from the file. |
497 * Default is r/w, can be set to r/o below. | 482 * Default is r/w, can be set to r/o below. |
498 * Don't reset it when in readonly mode | 483 * Don't reset it when in readonly mode |
645 /* Even though this is a new file, it might have been | 630 /* Even though this is a new file, it might have been |
646 * edited before and deleted. Get the old marks. */ | 631 * edited before and deleted. Get the old marks. */ |
647 check_marks_read(); | 632 check_marks_read(); |
648 #endif | 633 #endif |
649 #ifdef FEAT_MBYTE | 634 #ifdef FEAT_MBYTE |
650 if (eap != NULL && eap->force_enc != 0) | 635 /* Set forced 'fileencoding'. */ |
651 { | 636 if (eap != NULL) |
652 /* set forced 'fileencoding' */ | 637 set_forced_fenc(eap); |
653 fenc = enc_canonize(eap->cmd + eap->force_enc); | |
654 if (fenc != NULL) | |
655 set_string_option_direct((char_u *)"fenc", -1, | |
656 fenc, OPT_FREE|OPT_LOCAL, 0); | |
657 vim_free(fenc); | |
658 } | |
659 #endif | 638 #endif |
660 #ifdef FEAT_AUTOCMD | 639 #ifdef FEAT_AUTOCMD |
661 apply_autocmds_exarg(EVENT_BUFNEWFILE, sfname, sfname, | 640 apply_autocmds_exarg(EVENT_BUFNEWFILE, sfname, sfname, |
662 FALSE, curbuf, eap); | 641 FALSE, curbuf, eap); |
663 #endif | 642 #endif |
2736 eap->read_edit = FALSE; | 2715 eap->read_edit = FALSE; |
2737 eap->forceit = FALSE; | 2716 eap->forceit = FALSE; |
2738 return OK; | 2717 return OK; |
2739 } | 2718 } |
2740 | 2719 |
2741 #ifdef FEAT_MBYTE | 2720 /* |
2721 * Set default or forced 'fileformat' and 'binary'. | |
2722 */ | |
2723 void | |
2724 set_file_options(set_options, eap) | |
2725 int set_options; | |
2726 exarg_T *eap; | |
2727 { | |
2728 /* set default 'fileformat' */ | |
2729 if (set_options) | |
2730 { | |
2731 if (eap != NULL && eap->force_ff != 0) | |
2732 set_fileformat(get_fileformat_force(curbuf, eap), OPT_LOCAL); | |
2733 else if (*p_ffs != NUL) | |
2734 set_fileformat(default_fileformat(), OPT_LOCAL); | |
2735 } | |
2736 | |
2737 /* set or reset 'binary' */ | |
2738 if (eap != NULL && eap->force_bin != 0) | |
2739 { | |
2740 int oldval = curbuf->b_p_bin; | |
2741 | |
2742 curbuf->b_p_bin = (eap->force_bin == FORCE_BIN); | |
2743 set_options_bin(oldval, curbuf->b_p_bin, OPT_LOCAL); | |
2744 } | |
2745 } | |
2746 | |
2747 #if defined(FEAT_MBYTE) || defined(PROTO) | |
2748 /* | |
2749 * Set forced 'fileencoding'. | |
2750 */ | |
2751 void | |
2752 set_forced_fenc(eap) | |
2753 exarg_T *eap; | |
2754 { | |
2755 if (eap->force_enc != 0) | |
2756 { | |
2757 char_u *fenc = enc_canonize(eap->cmd + eap->force_enc); | |
2758 | |
2759 if (fenc != NULL) | |
2760 set_string_option_direct((char_u *)"fenc", -1, | |
2761 fenc, OPT_FREE|OPT_LOCAL, 0); | |
2762 vim_free(fenc); | |
2763 } | |
2764 } | |
2765 | |
2742 /* | 2766 /* |
2743 * Find next fileencoding to use from 'fileencodings'. | 2767 * Find next fileencoding to use from 'fileencodings'. |
2744 * "pp" points to fenc_next. It's advanced to the next item. | 2768 * "pp" points to fenc_next. It's advanced to the next item. |
2745 * When there are no more items, an empty string is returned and *pp is set to | 2769 * When there are no more items, an empty string is returned and *pp is set to |
2746 * NULL. | 2770 * NULL. |