Post Reply 
Load HP50 program to NewRPL machine?
03-24-2020, 12:49 PM
Post: #4
RE: Load HP50 program to NewRPL machine?
Regarding the replacement of digraphs:

Users of Sublime Text can use my custom command:
Code:

import sublime
import sublime_plugin

class NewrplCommand(sublime_plugin.TextCommand):
    def replace_region(self, edit, region):
        if not region.empty():
            string = self.view.substr(region)
            string = string.replace('<<', '«')
            string = string.replace('>>', '»')
            string = string.replace('->', '→')
            self.view.replace(edit, region, string)

    def replace_selections(self, view, edit):
        for region in self.view.sel():
            self.replace_region(edit, region)

    def replace_buffer(self, view, edit):
        region = sublime.Region(0, self.view.size())
        self.replace_region(edit, region)

    def run(self, edit):
        # check if something is selected
        count = sum(1 for _ in self.view.sel())
        if count == 0: # Should not happen
            self.replace_buffer(self.view, edit)
        elif count == 1:
            # Check if first and only element is just cursor
            region = next(iter(self.view.sel()))
            if region.empty():
                self.replace_buffer(self.view, edit)
            else:
                self.replace_selections(self.view, edit)
        else:
            self.replace_selections(self.view, edit)
This code can be stored as "newrpl.py" in The Packages/User folder.

Activation can be done with a key binding like this one:
Code:
{"keys": ["ctrl+t"], "command": "newrpl"}

The command uses the whole buffer if no selections exist, else replacement is only made in selections.
An improvement would be to only replace outside of strings when using the whole buffer.
Hope this helps someone.
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: Load HP50 program to NewRPL machine? - erazor - 03-24-2020 12:49 PM



User(s) browsing this thread: 1 Guest(s)