Giter Site home page Giter Site logo

Comments (3)

alankilborn avatar alankilborn commented on May 30, 2024 1

Undo is really only for changes affecting textual content of your document. As bookmarking only affect the margin, it isn't eligible to be part of undo.

from notepad-plus-plus.

santropedro avatar santropedro commented on May 30, 2024

@dogslife What do you mean by "search DD menu"? Also which of the two you mean by "previously book marked lines"=$? Because if you want $ bookmarked back: I have two ideas: if you need to bookmark certain lines you can precisely describe with a regex, and it sounds like comments could be and console.log too (I don't know js, I'm guessing), that regex won't be hard and you can ask someone for it, and I imagine it would work always in any file (it would have to be precise and well done of course). The other is: What if you after deleting the bookmarked lines, invert all bookmarks so all are selected, do ctrl+z and then invert again, that will bookmark $. But if you meant you wanted your first bookmarks, then why don't you just instead open a new document, paste all the same text, and do the operations starting with "I clear bookmarks" there? Then at the end you throw that away, and the original file hasn't been touched, still has all the bookmarks. On the other hand, I agree that the feature to add sounds incompatible with some of the mechanics of npp.

from notepad-plus-plus.

mpheath avatar mpheath commented on May 30, 2024

@dogslife The PythonScript plugin might be able to help to reduce the effort of you current actions.

The list of saved bookmarks are inserted into a dictionary with filename as the key to access. So, New 1 is a backup filename and C:\index.js would be an actual filename. This allows saving of bookmarks for each buffer by it's associated filename.

Only // javascript line comments are recognized, not multiline /* */ comments.

Directions:

  1. Run script to save bookmarks and optionally choose to add bookmarks for javascript comments...
  2. If new added bookmarks are OK, use Menu: Search -> Bookmark -> Remove bookmark lines to remove lines.
  3. Test the document in browser and then manually save as cleaned document to pre prod folder.
  4. Undo document back to the origin state of bookmarks which were saved.
  5. Run script to restore bookmarks.

Test on a sample file first to ensure working to expectation!

# Save and restore bookmarks in Notepad++.
# After bookmarks saved, prompts to bookmark
# javascript '//' comments and console.log() lines.
# https://community.notepad-plus-plus.org/topic/23039/faq-how-to-install-and-run-a-script-in-pythonscript/1
# https://github.com/notepad-plus-plus/notepad-plus-plus/issues/14891

from Npp import editor, notepad, LANGTYPE, MESSAGEBOXFLAGS
import re


def main():
    BOOKMARK = 20
    mask = 1 << BOOKMARK
    title = 'PythonScript'
    filename = notepad.getCurrentFilename()
    message = ('Save' if not filename in savedBookmarks
               else 'Restore') + ' bookmarks?'

    result = notepad.messageBox(message, title, MESSAGEBOXFLAGS.YESNO)

    if result == MESSAGEBOXFLAGS.RESULTNO:
        if filename in savedBookmarks:
            message = 'Want to remove the saved bookmarks for this buffer?'
            result = notepad.messageBox(message, title,
                                        MESSAGEBOXFLAGS.YESNO|
                                        MESSAGEBOXFLAGS.DEFBUTTON2)

            if result == MESSAGEBOXFLAGS.RESULTYES:
                del savedBookmarks[filename]
        return

    if filename not in savedBookmarks:
        savedBookmarks[filename] = []

        # Save bookmarks.
        for i in range(editor.getLineCount()):
            if editor.markerGet(i) & mask:
                savedBookmarks[filename].append(i)

        # Clear bookmarks.
        editor.markerDeleteAll(BOOKMARK)

        # Bookmark javascript comments and console.log lines.
        if notepad.getCurrentLang() == LANGTYPE.JAVASCRIPT:
            message = 'Bookmark javascript comments and console.log lines?'
            result = notepad.messageBox(message, title, MESSAGEBOXFLAGS.YESNO)

            if result == MESSAGEBOXFLAGS.RESULTYES:
                re_comments = re.compile(r'[ \t]*//')
                re_consolelog = re.compile(r'\bconsole\.log\(.*?\);')

                for i in range(editor.getLineCount()):
                    line = editor.getLine(i)

                    if re_comments.match(line) or re_consolelog.search(line):
                        editor.markerAdd(i, BOOKMARK)
    else:

        # Clear bookmarks.
        editor.markerDeleteAll(BOOKMARK)

        # Restore bookmarks.
        for i in savedBookmarks[filename]:
            editor.markerAdd(i, BOOKMARK)

        # Remove the list of saved bookmarks.
        del savedBookmarks[filename]


try:
    savedBookmarks
except:
    savedBookmarks = {}

main()

from notepad-plus-plus.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.