From 0555f793f6638c297a022978fb0cfafd0a022c7e Mon Sep 17 00:00:00 2001 From: nadrad Date: Sun, 18 Sep 2022 13:48:51 +0200 Subject: [PATCH] styling -- uniform empty lines --- h-m-m | 62 +++++++++++++---------------------------------------------- 1 file changed, 13 insertions(+), 49 deletions(-) diff --git a/h-m-m b/h-m-m index 5ff3b71..ccd79df 100755 --- a/h-m-m +++ b/h-m-m @@ -151,7 +151,6 @@ const collapsed_symbol_on = "\033[38;5;215m"; const collapsed_symbol_off = "\033[0m"; - // }}} // {{{ checking the requirements @@ -221,7 +220,6 @@ function check_the_available_clipboard_tool(&$mm) } - // }}} // {{{ alternative screen @@ -267,7 +265,6 @@ function mput(&$mm,$x,$y,$s) } - // }}} // {{{ debug @@ -475,11 +472,9 @@ function load_file(&$mm) } - // }}} // {{{ calculate w, x, lh, and clh - function calculate_x_and_lh(&$mm, $id) { $node = $mm['nodes'][$id]; @@ -537,7 +532,6 @@ function calculate_x_and_lh(&$mm, $id) calculate_x_and_lh($mm, $cid); $mm['nodes'][$id]['clh'] += $mm['nodes'][$cid]['clh']; } - } @@ -592,8 +586,6 @@ function calculate_h(&$mm) } - - // }}} // {{{ calculate y and yo @@ -641,6 +633,7 @@ function calculate_children_y(&$mm,$pid) } } + // }}} // {{{ calculate top-down height shift @@ -655,7 +648,6 @@ function calculate_height_shift(&$mm, $id, $shift = 0) } - // }}} // {{{ draw connections on the map @@ -884,7 +876,6 @@ function add_content_to_the_map(&$mm, $id) } - // }}} // {{{ build map @@ -936,8 +927,6 @@ function build_map(&$mm) } - - // }}} // {{{ toggle @@ -954,7 +943,6 @@ function toggle(&$mm) } - // }}} // {{{ spacing adjuster @@ -1003,7 +991,6 @@ function adjust_width(&$mm, $task) } - // }}} // {{{ move nodes @@ -1039,7 +1026,6 @@ function push_node_down(&$mm, $id) } - // }}} // {{{ insert node @@ -1094,7 +1080,6 @@ function insert_node(&$mm, $type) } - // }}} // {{{ magic readline! @@ -1329,7 +1314,6 @@ function show_line(&$mm, $title, $cursor, $shift) } - // }}} // {{{ edit node @@ -1357,7 +1341,6 @@ function edit_node(&$mm, $rewrite = false) } - // }}} // {{{ center active node @@ -1419,7 +1402,6 @@ function go_to_bottom(&$mm) } - // }}} // {{{ search @@ -1435,9 +1417,9 @@ function search(&$mm) if (!next_search_result($mm)) previous_search_result($mm); - } + function previous_search_result(&$mm) { $cy @@ -1472,6 +1454,7 @@ function previous_search_result(&$mm) display($mm); } + function next_search_result(&$mm) { $cy @@ -1580,13 +1563,11 @@ function move_active_node_up(&$mm) } - // }}} // {{{ export html function export_html(&$mm) { - if (empty($mm['filename'])) { message($mm, "Can't export the map when it doesn't have a file name yet. Save it first."); @@ -1601,7 +1582,6 @@ function export_html(&$mm) return; } - fwrite ( $file @@ -1688,7 +1668,6 @@ function export_html_node(&$mm, $parent_id) } - // }}} // {{{ save @@ -1740,7 +1719,6 @@ function save(&$mm, $new_name = false) } - // }}} // {{{ message @@ -1812,6 +1790,7 @@ function push_change(&$mm) $mm['change_index']++; } + function undo(&$mm) { if($mm['change_index'] == 0) @@ -1825,6 +1804,7 @@ function undo(&$mm) display($mm); } + function redo(&$mm) { if(count($mm['changes']) == $mm['change_index']) @@ -1838,6 +1818,7 @@ function redo(&$mm) display($mm); } + // }}} // {{{ change active node @@ -1880,7 +1861,6 @@ function change_active_node(&$mm, $direction) return; } - // no other movement applies to the root element if ( $mm['active_node']==0 ) return; @@ -1894,7 +1874,6 @@ function change_active_node(&$mm, $direction) return; } - // for up and down, we'll try to move between siblings first, // considering that their order is set based on their list // in the parent item. @@ -1920,7 +1899,6 @@ function change_active_node(&$mm, $direction) return; } - // if it's not possible to move up or down between siblings, // we'll measure distance and move to the nearest node. // because the goal is to move vertically, and also because @@ -1952,7 +1930,6 @@ function change_active_node(&$mm, $direction) } - // }}} // {{{ expand @@ -2013,13 +1990,11 @@ function append(&$mm) } - // }}} // {{{ paste sub-tree function paste_sub_tree(&$mm, $as_sibling ) { - if ($as_sibling && $mm['active_node']==$mm['root']) return; if ($as_sibling) @@ -2055,7 +2030,6 @@ function paste_sub_tree(&$mm, $as_sibling ) if ($cdata['parent'] == $parent_id) $mm['nodes'][ $parent_id ]['children'][] = $cid; - // rearranging the items only if they are pasted as siblings // (for pasting as children, it makes sense to have them // at the end) @@ -2081,7 +2055,6 @@ function paste_sub_tree(&$mm, $as_sibling ) $mm['nodes'][ $parent_id ]['children'] = $children; } - $mm['active_node'] = $new_id; build_map($mm); @@ -2089,7 +2062,6 @@ function paste_sub_tree(&$mm, $as_sibling ) } - // }}} // {{{ clipboard @@ -2102,6 +2074,7 @@ function copy_to_clipboard(&$mm, $text) pclose($clip); } + function get_from_clipboard(&$mm) { return @@ -2139,6 +2112,7 @@ function yank_node(&$mm, $exclude_parent = false ) message($mm, 'Item(s) are copied to the clipboard.'); } + // }}} // {{{ delete @@ -2165,7 +2139,6 @@ function delete_node(&$mm, $exclude_parent = false, $dont_copy_to_clipboard = fa function delete_node_internal(&$mm, $active_node, $exclude_parent = false ) { - // taking a shorter approach if it's for the whole tree if ($active_node==$mm['root'] && !$exclude_parent) @@ -2175,7 +2148,6 @@ function delete_node_internal(&$mm, $active_node, $exclude_parent = false ) return; } - // if it's for a sub-tree, then... delete_children($mm, $active_node); @@ -2184,11 +2156,9 @@ function delete_node_internal(&$mm, $active_node, $exclude_parent = false ) { $mm['nodes'][ $active_node ]['is_leaf'] = true; $mm['nodes'][ $active_node ]['children'] = []; - } else { - $parent_id = $mm['nodes'][ $active_node ]['parent']; $previous_sibling = 0; @@ -2242,19 +2212,21 @@ function delete_children(&$mm,$id) function toggle_focus(&$mm) { $mm['focus_lock'] = !$mm['focus_lock']; - + message($mm, $mm['focus_lock'] ? 'Focus locked' : 'Focus unlocked'); build_map($mm); display($mm); } + function focus(&$mm) { collapse_siblings($mm, $mm['active_node']); expand_siblings($mm, $mm['active_node']); } + function collapse_siblings(&$mm, $id) { if ($id <= $mm['root']) return; @@ -2279,7 +2251,6 @@ function expand_siblings(&$mm, $id) } - // }}} // {{{ collapse @@ -2348,11 +2319,9 @@ function collapse(&$mm, $id, $keep) foreach ($mm['nodes'][$id]['children'] as $cid) collapse($mm, $cid, $keep-1); } - } - function collapse_level(&$mm, $level, $no_display = false) { collapse($mm, $mm['root'], $level); @@ -2381,7 +2350,6 @@ function collapse_level(&$mm, $level, $no_display = false) } - // }}} // {{{ display @@ -2403,7 +2371,6 @@ function display(&$mm, $force_center = false) $blank = str_repeat(' ', $mm['terminal_width']); - // calculating the coordinates of the active node $x1 = @@ -2438,7 +2405,6 @@ function display(&$mm, $force_center = false) + $y1 ; - // building the output $output = ''; @@ -2551,7 +2517,6 @@ function display(&$mm, $force_center = false) } - // }}} // {{{ monitor key presses @@ -2567,7 +2532,6 @@ function monitor_key_presses(&$mm) switch ($in) { - case 'a': edit_node($mm); break; case 'A': edit_node($mm, true); break; @@ -2666,9 +2630,9 @@ function monitor_key_presses(&$mm) case "\n": insert_node($mm, insert_sibling); break; case "\t": insert_node($mm, insert_child); break; - } + // uncomment the following to discover the escape codes: // move(1,1); // for ($i=0; $i