Community
    • 登入

    How to see hex value of character next to cursor?

    已排程 已置頂 已鎖定 已移動 Help wanted · · · – – – · · ·
    26 貼文 6 Posters 11.5k 瀏覽
    正在載入更多貼文
    • 從舊到新
    • 從新到舊
    • 最多點贊
    回覆
    • 在新貼文中回覆
    登入後回覆
    此主題已被刪除。只有擁有主題管理權限的使用者可以查看。
    • EkopalypseE
      Ekopalypse @Jeff Heath
      最後由 編輯

      @Jeff-Heath

      That sounds strange, because normally you have it available.
      I’ve never had a problem installing it, and I do it this way with every new npp version. I think I’ve been doing this since 7.9.5, which is how my automated tests run.
      The only reason I can think of why it doesn’t show up in the Available tab is if npp thinks it has already found something.

      Jeff HeathJ 1 條回覆 最後回覆 回覆 引用 0
      • Jeff HeathJ
        Jeff Heath @Ekopalypse
        最後由 編輯

        @Ekopalypse Thanks for your feedback. I’ve got the script working now, and I’ll worry later about getting Python Script running on a new install.

        Alan KilbornA 1 條回覆 最後回覆 回覆 引用 1
        • Alan KilbornA
          Alan Kilborn @Jeff Heath
          最後由 Alan Kilborn 編輯

          @Jeff-Heath

          A really good up-to-date thread for things PythonScript is HERE. The bulk of your problem might have been trying to follow old, outdated PS information. Not sure how to solve the problem of outdated info in old threads here…

          1 條回覆 最後回覆 回覆 引用 0
          • Jeff HeathJ
            Jeff Heath
            最後由 Jeff Heath 編輯

            Thanks all for your input. I’ve made a few edits to produce the format I wanted for the output, and changes which I think make the code more readable (including adding a few comments). In case this is helpful for anyone else, here it is:

            # encoding=utf-8
            
            def callback_sci_UPDATEUI(args):
                # get character (as an integer) at the current position
                c = editor.getCharAt(editor.getCurrentPos())
                if c == 0:
                    info = 'END-OF-FILE'
                elif c in [10,13]:
                    info = "U+{0:04X} LINE-ENDING".format(c)
                else:
                    # not one of the special cases
                    if 1 <= c <= 255:
                        # simple ANSI character
                        s = unichr(c)
                    else:
                        # more complex case, so get the text range
                        pos = editor.getCurrentPos()
                        pos2 = editor.positionAfter(pos)
                        s = editor.getTextRange(pos,pos2).decode('utf-8')
                        # handle wide ordinals https://stackoverflow.com/a/7291240/5508606
                        if len(s) != 2:
                            c = ord(s)
                        else:
                            c = 0x10000 + (ord(s[0]) - 0xD800) * 0x400 + (ord(s[1]) - 0xDC00)
                    
                    # produce desired format for the status bar
                    try:
                        info = "U+{0:04X} '{1}'".format(c, s.encode('utf-8'))
                    except:
                        info = "U+????"
                
                notepad.setStatusBar(STATUSBARSECTION.DOCTYPE, info)
            
            #callback_sci_UPDATEUI(None)     # per https://notepad-plus-plus.org/community/topic/17799/, want on-demand
            editor.callback(callback_sci_UPDATEUI, [SCINTILLANOTIFICATION.UPDATEUI]) # per https://notepad-plus-plus.org/community/topic/14767/, want live
            

            I haven’t tested with any characters outside the BMP, but I think I transformed the code properly. Someone who works with those characters can feel free to test it…

            Alan KilbornA 1 條回覆 最後回覆 回覆 引用 0
            • Alan KilbornA
              Alan Kilborn @Jeff Heath
              最後由 編輯

              @Jeff-Heath

              There is also a plugin (at least one) that can provide the functionality you seek. It’s called GotoLineCol in PluginsAdmin and it shows you this:

              1f4be7c7-9054-4ff5-b7c9-3bbe4b82cc95-image.png

              when your caret is next to a 💙 character.

              1 條回覆 最後回覆 回覆 引用 0
              • PeterJonesP
                PeterJones @Jeff Heath
                最後由 PeterJones 編輯

                @Jeff-Heath said in How to see hex value of character next to cursor?:

                I’ve followed the installing PythonScript Guide,

                FYI: that guide from 2019 was focused on the brief time when Notepad++ had just come out of a confusing update, and not all plugins (including Python Script) were yet compatible with the new Plugins Admin method of installing plugins. PythonScript v1.5, released in Oct 2019, was the first PS version compatible with Notepad++'s Plugins Admin interface… but that means that PythonScript has been available through the default interface Since Oct 2019. You no longer need to follow that ancient guide.

                update: sorry, apparently it wasn’t fully compatible until v1.5.1, also in October 2019; it was first listed in Plugins Admin in Notepad++ v7.8.1 – so from that point on, you don’t need to follow that outdated guide.

                f798369e-eab4-4bb7-9851-c17db123cd8e-image.png

                1 條回覆 最後回覆 回覆 引用 2
                • 第一個貼文
                  最後的貼文
                The Community of users of the Notepad++ text editor.
                Powered by NodeBB | Contributors