diff --git a/Preferences.sublime-settings b/Preferences.sublime-settings index 1a8cc009..495725f4 100644 --- a/Preferences.sublime-settings +++ b/Preferences.sublime-settings @@ -40,6 +40,16 @@ // Adds after list items instead of a single . "mde.list_align_text": false, + // MarkdownEditing (References): + // The sorting method used by the Organize References command. + // Should be one of + // + // 'marker_order': List in order of appearance in document + // 'alphabetical': Alphabetical based on reference name, sorting numerals lexagraphically + // 'numeric': Alphabetical based on reference name, sorting numeral chunks numerically + "mde.ref_organize_sort": "marker_order", + "mde.ref_organize_sort_reverse": false, + // MarkdownEditing: // Automatically switches list bullet when indenting blank list item with . "mde.list_indent_auto_switch_bullet": true, diff --git a/plugins/references.py b/plugins/references.py index 76b87ba8..8151e5c8 100644 --- a/plugins/references.py +++ b/plugins/references.py @@ -541,9 +541,21 @@ def run(self, edit): flatrefs.append((name, view.substr(line_reg).strip("\n"))) sel.add(line_reg) + sorting_funcs = { + "marker_order": lambda x: marker_order[x[0].lower()] + if x[0].lower() in marker_order + else 9999, + "alphabetical": lambda x: x[0].lower(), + "numeric": lambda x: [ + int(p) if p.isnumeric() else p for p in re.split(r"[ _.-]", x[0].lower()) + ], + } + settings = view.settings() + flatfns.sort(key=operator.itemgetter(0)) flatrefs.sort( - key=lambda x: marker_order[x[0].lower()] if x[0].lower() in marker_order else 9999 + key=sorting_funcs[settings.get("mde.ref_organize_sort", "marker_order")], + reverse=settings.get("mde.ref_organize_sort_reverse", False), ) view.run_command("left_delete")