Ticket #1480: mc.1480.diff

File mc.1480.diff, 5.7 KB (added by szaszg, 6 years ago)

New patch for master branch

  • doc/man/mcedit.1.in

    diff --git a/doc/man/mcedit.1.in b/doc/man/mcedit.1.in
    index d451cf6..192304a 100644
    a b deleting, navigating, typing) 
    588588Search autocomplete candidates in entire of file or just from 
    589589begin of file to cursor position (0) 
    590590.TP 
     591.I editor_smart_home_end 
     592when option switched on: 
     593the Home key go to the first column on first press, and after second 
     594press go to the beginning of non-whitespace char and 
     595the End key go to the last column on first press, and after second 
     596press go to the end of non-whitespace char. 
     597.TP 
    591598.I spell_language 
    592599Spelling language (en, en\-variant_0, ru, etc) installed with aspell 
    593600package (a full list can be get using 'aspell' utility). 
  • src/editor/edit.c

    diff --git a/src/editor/edit.c b/src/editor/edit.c
    index 2cd91c9..b281e64 100644
    a b int option_cursor_beyond_eol = 0; 
    9090int option_line_state = 0; 
    9191int option_line_state_width = 0; 
    9292gboolean option_cursor_after_inserted_block = FALSE; 
     93int option_smart_home_end = 0; 
    9394 
    9495int option_edit_right_extreme = 0; 
    9596int option_edit_left_extreme = 0; 
    edit_move_to_bottom (WEdit * edit) 
    942943    } 
    943944} 
    944945 
     946/** returns index of first char on line or the first nonspace char */ 
     947 
     948static long 
     949edit_bol_var (WEdit * edit, long current) 
     950{ 
     951    long tmp; 
     952    int b; 
     953 
     954    if (!option_smart_home_end) 
     955        return edit_bol (edit, current); 
     956 
     957    if (current < 0) 
     958        current = 0; 
     959 
     960    if (edit_get_byte (edit, current - 1) != '\n')      /* not at BOL */ 
     961        return edit_bol (edit, current); 
     962 
     963    if (edit_get_byte (edit, current) == '\n')  /* on an empty line */ 
     964        return current; 
     965 
     966    for (tmp = current; (b = edit_get_byte (edit, tmp)) != '\n'; tmp++) 
     967    { 
     968        if (!isspace (b)) 
     969            return tmp; 
     970    } 
     971    return current; 
     972} 
     973 
     974/* --------------------------------------------------------------------------------------------- */ 
     975/** returns index of last char on line or the last nonspace char */ 
     976static long 
     977edit_eol_var (WEdit * edit, long current) 
     978{ 
     979    long tmp; 
     980    int b; 
     981 
     982    if (!option_smart_home_end) 
     983        return edit_eol (edit, current); 
     984 
     985    if (current >= edit->last_byte) 
     986        current = edit->last_byte; 
     987 
     988    if (edit_get_byte (edit, current) != '\n')  /* not at BOL */ 
     989        return edit_eol (edit, current); 
     990 
     991    if (edit_get_byte (edit, current - 1) == '\n')      /* on an empty line */ 
     992        return current; 
     993 
     994    for (tmp = current - 1; (b = edit_get_byte (edit, tmp)) != '\n'; tmp--) 
     995    { 
     996        if (!isspace (b)) 
     997            return tmp + 1; 
     998    } 
     999    return current; 
     1000} 
     1001 
    9451002/* --------------------------------------------------------------------------------------------- */ 
    9461003/** goto beginning of line */ 
    9471004 
    9481005static void 
    9491006edit_cursor_to_bol (WEdit * edit) 
    9501007{ 
    951     edit_cursor_move (edit, edit_bol (edit, edit->curs1) - edit->curs1); 
     1008    edit_cursor_move (edit, edit_bol_var (edit, edit->curs1) - edit->curs1); 
    9521009    edit->search_start = edit->curs1; 
    9531010    edit->prev_col = edit_get_col (edit); 
    9541011    edit->over_col = 0; 
    edit_cursor_to_bol (WEdit * edit) 
    9601017static void 
    9611018edit_cursor_to_eol (WEdit * edit) 
    9621019{ 
    963     edit_cursor_move (edit, edit_eol (edit, edit->curs1) - edit->curs1); 
     1020    edit_cursor_move (edit, edit_eol_var (edit, edit->curs1) - edit->curs1); 
    9641021    edit->search_start = edit->curs1; 
    9651022    edit->prev_col = edit_get_col (edit); 
    9661023    edit->over_col = 0; 
  • src/editor/edit.h

    diff --git a/src/editor/edit.h b/src/editor/edit.h
    index 3ff1860..0b9ebe3 100644
    a b extern int visible_tws; 
    5656extern int simple_statusbar; 
    5757extern int option_check_nl_at_eof; 
    5858extern int show_right_margin; 
     59extern int option_smart_home_end; 
    5960 
    6061/*** declarations of public functions ************************************************************/ 
    6162 
  • src/editor/editoptions.c

    diff --git a/src/editor/editoptions.c b/src/editor/editoptions.c
    index 4ab2aea..4e7195c 100644
    a b edit_options_dialog (WDialog * h) 
    151151                QUICK_STOP_GROUPBOX, 
    152152                QUICK_SEPARATOR (FALSE), 
    153153                QUICK_SEPARATOR (FALSE), 
     154                QUICK_SEPARATOR (FALSE), 
    154155                QUICK_START_GROUPBOX (N_("Tabulation")), 
    155156                    QUICK_CHECKBOX (N_("&Fake half tabs"), &option_fake_half_tabs, NULL), 
    156157                    QUICK_CHECKBOX (N_("&Backspace through tabs"), &option_backspace_through_tabs, 
    edit_options_dialog (WDialog * h) 
    168169                    QUICK_CHECKBOX (N_("Save file &position"), &option_save_position, NULL), 
    169170                    QUICK_CHECKBOX (N_("&Visible trailing spaces"), &visible_tws, NULL), 
    170171                    QUICK_CHECKBOX (N_("Visible &tabs"), &visible_tabs, NULL), 
     172                    QUICK_CHECKBOX (N_("Smart &Home/End key behavior"), &option_smart_home_end, NULL), 
    171173                    QUICK_CHECKBOX (N_("Synta&x highlighting"), &option_syntax_highlighting, NULL), 
    172174                    QUICK_CHECKBOX (N_("C&ursor after inserted block"), &option_cursor_after_inserted_block, NULL), 
    173175                    QUICK_CHECKBOX (N_("Pers&istent selection"), &option_persistent_selections, 
  • src/setup.c

    diff --git a/src/setup.c b/src/setup.c
    index 1e5e8c6..bf44a74 100644
    a b static const struct 
    344344    { "editor_option_auto_para_formatting", &option_auto_para_formatting }, 
    345345    { "editor_option_typewriter_wrap", &option_typewriter_wrap }, 
    346346    { "editor_edit_confirm_save", &edit_confirm_save }, 
     347    { "editor_smart_home_end", &option_smart_home_end }, 
    347348    { "editor_syntax_highlighting", &option_syntax_highlighting }, 
    348349    { "editor_persistent_selections", &option_persistent_selections }, 
    349350    { "editor_cursor_beyond_eol", &option_cursor_beyond_eol },