How to prevent text to be modified

Everything related to our flagship word processor.
Post Reply
lellius
Posts: 54
Joined: 2002-08-15 22:06:44

How to prevent text to be modified

Post by lellius »

Is there in Nisus a command to block a text section and to prevent it to be modified?
Thanks
adryan
Posts: 561
Joined: 2014-02-08 12:57:03
Location: Australia

Re: How to prevent text to be modified

Post by adryan »

G'day, lellius et al

I am unaware of any such command.

One possible workaround would be to take a screenshot of the text block (with Show Invisibles turned off) and insert the resultant image in the place of the original text. However, this would cause problems with Statistics (eg, word count), Table of Contents and Index. A possible ploy here might be to retain the original text but have it hide behind the inserted image. The original text would still be susceptible to alteration (such as document-wide color change), but such alteration would be invisible to the reader. Note, though, that any text hiding behind a Shape can still be found by the Find mechanism.

Any use of images will make the appearance and pagination of the document vulnerable to subsequent alterations to any preceding portion of the document, so it may be better to defer it until the document is all but complete.

Converting a document to PDF before distribution would give at least some measure of protection against further alteration, but security of this type is a whole other subject.

Cheers,
Adrian
MacBook Pro (M1 Pro, 2021)
macOS Ventura
Nisus Writer user since 1996
lellius
Posts: 54
Joined: 2002-08-15 22:06:44

Re: How to prevent text to be modified

Post by lellius »

Adrian,
Thanks for the answer. This is however a bit intricate for to my modest skills.
The best solution would be perhaps a hint to Martin, to create a new command in the next release like “Prevent Modifying Text In Selection”, similar to Prevent Check Spelling in Selection.
lellius
Nisus user since Nisus Writer 3 (old timer).
adryan
Posts: 561
Joined: 2014-02-08 12:57:03
Location: Australia

Re: How to prevent text to be modified

Post by adryan »

G'day, lellius et al

I've given this problem more thought, as I've found it intriguing.

I suspect that some sort of "Spare Me" command might be difficult to implement. Footnote numbering comes to mind, but there could well be other issues whereby certain aspects of the text to be spared alteration may themselves need to be spared from being spared, if you get my drift.

A lot depends on the reason for "locking" a given chunk of text.

If the intent is to prevent alteration by another party, the techniques I mentioned in my previous posting may help somewhat. Such protection is, of course, relative and not guaranteed as absolute.

If the intent is to prevent inadvertent alteration, that's served by Undo commands and backups.

If the intent is to remove the given text from further consideration (ie, to deem it as part of the final draft), a simple text coloration may suffice to distinguish it from the rest of the document. You might, for example, have text colored red while it is under active consideration and then changed to black when you are satisfied with it. Colored text is immediately apparent to the eye, but it is also easily retrieved by the Find system.

It is as well to bear in mind the Invert Selection command (in the Edit menu) which could have its uses here. For example, you can select a paragraph and then invoke the Invert Selection command. Find/Replace operations can then (by choosing the scope as "In Selection") be confined to text other than that you wish to be preserved, as can other operations (such as many involving formatting) that require a selection for their argument. As long as the text to be preserved is distinguishable in some way (color, font, Style, whatever), all such text can easily be found before application of the Invert Selection operation.

Desktop publishing applications usually have a system of linked text boxes. In these situations it is often possible to isolate a chunk of text by containing it within a text box that is excluded from the main chain. Many operations (including Find/Replace) confine themselves to the chain from which they are invoked. To this extent, text outside the main chain can be preserved, immune to operations applied elsewhere. Note that this is not the case with Text Boxes in Nisus Writer where, for example, Find & Replace does not discriminate between text in Text Boxes and text elsewhere.

Cheers,
Adrian
MacBook Pro (M1 Pro, 2021)
macOS Ventura
Nisus Writer user since 1996
lellius
Posts: 54
Joined: 2002-08-15 22:06:44

Re: How to prevent text to be modified

Post by lellius »

Hi, Adrian
My intent is indeed to prevent inadvertent alteration of a certain text block.
Suppose I have a very long text, two or three books in the size, which I must keep together in one file only.
Suppose I have to make multiple changes in the file, but not in that certain text block, which I have already considered as finished.
It would be boring enough to perform Find/Replace changes, occurrence by occurrence.
Suppose more I have a citation with a spelling error in original, which should then be preserved and prevented to be corrected. An other example. Sometimes a word differs by just the final vowel switching from one language to another, where I want to mark the reference to that specific language.
My English is not so good, so i can’t go on with other examples.
Hence the request of a command like “Prevent Modifying Text in a text selection” or in a text previously blocked as finished.
But as you said, this feature might be difficult to implement.
I just imagined it could be not very different from the implementation “Prevent Check Spelling in Selection”.
Anyway thanks again.
lellius
adryan
Posts: 561
Joined: 2014-02-08 12:57:03
Location: Australia

Re: How to prevent text to be modified

Post by adryan »

G'day, lellius et al

Thanks for explaining your reasons for wanting to prevent modification of chunks of text.

In such circumstances, I think that a hardwired "Set in Concrete" command could be too heavy-handed. I've already mentioned footnote numbering as a possible stumbling block. At some stage you may want to alter the formatting (font, kerning, etc) even though you don't want to alter the underlying character sequence. My own preference would be to allow for some flexibility (although this may not suit everyone).

I would be inclined to use two special Styles in conjunction with the Invert Selection command. These Styles would serve only to flag text: they would not actually modify it in any way.

One Style might be called something like "Spare from Spelling Check"; the other might be called something like "Spare from Alteration". A Style related to spelling offers more flexibility than the "Prevent Check Spelling in Selection" command. With a Style, you can use Style-related commands from the Format menu, for example. And it's a bit easier to understand what you are doing in a Find situation. I've suggested having these two independent Styles because having a separate Style related to spelling could be handy in multilingual documents.

At any time, you can easily find text to which one or both of these Styles has been applied. Of course, you could if you wished incorporate some visibly distinguishing feature (such as text color) in your definition of the "Spare from Alteration" Style.

The main threat to text you wish to preserve from alteration comes from global application of Find & Replace or formatting commands. To counter this threat, I suggest creating a Macro called something like "Select All Except". This would be a two-line Macro which first finds all text subject to the "Spare from Alteration" Style and then inverts the selection. You then just get into the habit of invoking this Macro (probably via a keyboard shortcut) before performing some global operation. You might even assign it the Cmd-A shortcut usually reserved for "Select All" and use some other keystroke combination for "Select All". In Find & Replace you would use the "In Selection" option.

When it comes to spelling, you wouldn't use the Macro. You would just find all the text subject to the "Spare from Spelling Check" Style, then use the "Prevent Check Spelling in Selection" command before doing the spelling check.

Note that this approach does not afford text automatic protection from alteration. But, with care, you can have your cake and eat it too.

Cheers,
Adrian
MacBook Pro (M1 Pro, 2021)
macOS Ventura
Nisus Writer user since 1996
lellius
Posts: 54
Joined: 2002-08-15 22:06:44

Re: How to prevent text to be modified

Post by lellius »

Adrian,
thanks for your long and detailed answer, but I must admit that my English is not good enough to easily understand your long explanation. Matter is also a bit complicated. Therefore I will take time to better understand everything and to try some attempts according to your suggestions.
However, allow me to come back again to the point:
a command like “Skip Selected Text Block with Find/Replace” or “Prevent Modifying Text in Selection” would solve any problem and would be also very simple to use.
Is it really so difficult to implement it?
lellius
adryan
Posts: 561
Joined: 2014-02-08 12:57:03
Location: Australia

Re: How to prevent text to be modified

Post by adryan »

G’day, lellius et al

I’m sorry if I’ve complicated things too much. I’ll try to simplify.

Any command that completely prevents text from being modified would have to come from Nisus. This may not happen any time soon. My suggestions offer ways to work with what we have now.

Try this:–

(1) Create a Character Style called “Skip Me”. Make sure it has no special features and make it “Based on None”. Add it to the Style Library so you can use it in other documents.

(2) Create a Macro called "Select All Except". It has two lines:–

Find All @Text<(?:.|\n|\f)+>, 'Eau'
Invert Selection

In the first line, you need to apply the “Skip Me” Style to the string between “<“ and ”>”, but don’t include “<“ or ”>”. Now save the Macro.

(3) Select some text in a Nisus test document. Apply the “Skip Me” Style to it.

(4) Run the "Select All Except" Macro. Everything should now be selected except the text with the “Skip Me” Style applied to it.

(5) Use Find & Replace to do something (such as underline all text) with “Where” set to “In Selection”. Everything should now be underlined except the text with the “Skip Me” Style applied to it.

That’s it. It’s easy to do. It would be even easier if you used keyboard shortcuts to apply the “Skip Me” Style and to run the "Select All Except" Macro.

I also suggested you use the "Select All Except" Macro routinely instead of the "Select All" command in the Edit menu. Appropriate keyboard shortcuts would help here too.

I hope this helps to show a way to do what you want.

Cheers,
Adrian
MacBook Pro (M1 Pro, 2021)
macOS Ventura
Nisus Writer user since 1996
lellius
Posts: 54
Joined: 2002-08-15 22:06:44

Re: How to prevent text to be modified

Post by lellius »

Hi Adrian,
Your explanation is very clear and easy to be understood also by me.
I followed your instructions, and — indeed — your method works well.
Using keyboard shortcuts it goes also quickly.
Maybe some attention is recommended while using Find & Replace: never forget to set “in Selection”.
Also don't forget to provide your “Nisus New File.dot” with the Character Style “Skip Me”. (I spent some time, to realise it).
In short, thanks again. Happy New Year to you.
lellius
adryan
Posts: 561
Joined: 2014-02-08 12:57:03
Location: Australia

Re: How to prevent text to be modified

Post by adryan »

G’day, lellius et al

I’m very pleased it works for you.

I will now offer some comments on the Find & Replace system in Nisus Writer because they are particularly pertinent in the current context.

The problem with Find & Replace settings is a recurring one. The parameters remain the same until you change them, which is often convenient. It is less convenient, however, if you do wish to change them. At the very least, I would like to have the option to set the scope to “In Selection” using a modifier key. This could operate similarly to the Close All command in the File menu: holding down the Option key while viewing the File menu changes the Close command to the Close All command. (It is important, too, that such a modified command appear in the Menu Keys Preferences panel in the same way as Close All does.)

I know of no inbuilt way to reset all the Find & Replace parameters to some default set. One possible workaround would be to do a dummy search with parameters set the way you want them. Any Macro that did this would need to save any selection beforehand and restore it afterwards. If the “Cmd-F” shortcut were reassigned to this Macro, Find & Replace operations would use the chosen parameters as the default. Because of the parameter persistence nature of the Find & Replace window, it’s not entirely clear to me whether such a Macro would need to begin with a Show Find command as well as end with one. One of our Macro experts may care to favor us with a Macro that resets Find & Replace parameters. :-) Such a Macro would be a very useful addition to the Macro library. Ideally, though, one would be able to tailor a default set of parameters in a Preferences panel and restore that set at any time via a command in the Find menu.

In this situation of preventing modification of particular bits of text, it is important (as lellius has mentioned) to restrict Find & Replace to “In Selection”. Reassigning the “Cmd-F” shortcut as I have suggested above would be one way to achieve this without having to think about it each time.

And Happy New Year to you too, lellius (et al!).

Cheers,
Adrian
MacBook Pro (M1 Pro, 2021)
macOS Ventura
Nisus Writer user since 1996
User avatar
phspaelti
Posts: 1313
Joined: 2007-02-07 00:58:12
Location: Japan

Re: How to prevent text to be modified

Post by phspaelti »

adryan wrote: 2019-12-27 14:30:09I know of no inbuilt way to reset all the Find & Replace parameters to some default set.
From the macro reference (under Find and Replace options):
    !    Copy text/options into the Find & Replace dialog instead of doing an actual find/replace.

So you can write a one line macro like this:

Code: Select all

Find '', '!e-i'
which will set the Find options to PowerFind and Ignore Case. It will also clear the find expression.
If you want to keep the current find expression, you can write the following:

Code: Select all

$find = Read Find Expression
Find $find, '!e-i'
Happy New Year to everyone.
philip
User avatar
phspaelti
Posts: 1313
Joined: 2007-02-07 00:58:12
Location: Japan

Re: How to prevent text to be modified

Post by phspaelti »

adryan wrote: 2019-12-27 14:30:09At the very least, I would like to have the option to set the scope to “In Selection” using a modifier key.
So a macro to do this would be:

Code: Select all

$find = Read Find Expression
Find $find, '!*s'
This uses the '*' to preserve all other options.
And a macro to reset to full document search would be:

Code: Select all

$find = Read Find Expression
Find $find, '!*W'
philip
User avatar
phspaelti
Posts: 1313
Joined: 2007-02-07 00:58:12
Location: Japan

Re: How to prevent text to be modified

Post by phspaelti »

adryan wrote: 2019-12-21 03:50:21 (2) Create a Macro called "Select All Except". It has two lines:–

Find All @Text<(?:.|\n|\f)+>, 'Eau'
Invert Selection

In the first line, you need to apply the “Skip Me” Style to the string between “<“ and ”>”, but don’t include “<“ or ”>”. Now save the Macro.
In order to avoid the need to mess around with styles in find expressions, try the following:

Code: Select all

$doc = Document.active
$skipStyle = $doc.styleWithName 'Skip Me'
Find All $skipStyle
Invert Selection
So now to combine Adrian's suggestions into one macro:

Code: Select all

# Find While Skip
$doc = Document.active
Document.setActive $doc
$skipStyle = $doc.styleWithName 'Skip Me'
if Find All $skipStyle
Invert Selection
else
Select All
end
$find = Read Find Expression
Find All $find, '*s'
This macro can be run from the find box and will do the Find All using the settings and expression from the dialog while respecting the "Skip Me" style. Notice that this macro will not actually change the restriction set in the Find dialog to "In Selection", so there is no need to toggle back and forth. It should be easy to write a similar macro to do Find and Replace All.
philip
adryan
Posts: 561
Joined: 2014-02-08 12:57:03
Location: Australia

Re: How to prevent text to be modified

Post by adryan »

G'day, Philip et al

Huge thanks, Philip, for these goodies.

Ah, the power of exclamation marks! Reminds me of my favorite programming language (Forth). So, with your first one-line Macro as a guide, it's easy to create (and store!) a Macro for restoring one's favorite Find & Replace parameters, which I have now done. (BTW, the option to Ignore Case should be "i", not "-i".) And I've done another one-liner to set the scope to "In Selection". For my own purposes, I prefer the expression fields to be blank when I open the Find & Replace window.

Just to clarify something for others: There's nothing wrong with using Styles in Find and Replace expressions when you're working in the Find & Replace window. But doing so in Macros is awkward, as my posted instructions attest. So Philip's approach with the Macro Language is a vast improvement here. It is much easier to see what is happening, without the need for any explanatory comments.

Philip's final Macro is interesting, in that it cleverly leaves the scope of Find operations in the dialog box unchanged. I also like the contained conditional. It is important to note, though, that running this Macro directly on a document could have unintended consequences if one does not already have in mind the expression currently occupying the "Find what" field (and that in the "Replace with" field if the Macro is modified accordingly). Of course, if the Find & Replace dialog box is opened before you run the Macro (as I think Philip intends), you can see what will happen, but I suspect there will be people who find this order of business somewhat at variance with their usual expectations.

Therefore, I propose the following version of Philip's Macro:–

Code: Select all

# Find While Skip
# Based on code written by Philip Spaelti.

$doc = Document.active
Document.setActive $doc
$skipStyle = $doc.styleWithName 'Skip Me'
if Find All $skipStyle
Invert Selection
# Options in the following line could be altered to reflect personal preference.
Replace All '', '', '!Eis'
else
# Options in the following line could be altered to reflect personal preference.
Replace All '', '', '!EiW'
end
Show Find
This Macro can be called directly from a document. It will reveal the Find & Replace dialog box with both expression fields blank (which is my own personal preference). If the document contains any text with the "Skip Me" Style applied to it, it will set the scope to "In Selection". If the document contains no such text, the scope is set to "Entire File". Because it has an inbuilt safety net, I think this Macro could well be assigned the Cmd-F shortcut and used as the default Find/Replace mechanism in Nisus Writer.

In the context of the problem originally posed by lellius, I myself would probably now proceed thus:–

(1) Create a Character Style called "Skip Me". Make sure it has no special features and make it "Based on None". Add it to the Style Library so you can use it in other documents. Incorporate it in the Nisus New File template if you wish.

(2) Create a Macro called "Find While Skip", using the above code.

(3) Re-assign the Cmd-F shortcut to this Macro.

(4) In any Nisus document, apply the "Skip Me" Style to whatever chunks of text you wish to preserve.

(5) Use Cmd-F for Find and/or Replace operations (in any document) as you normally would.

It is important to realize that we have strayed somewhat from my original procedure which was meant to cover a wider variety of situations. Those situations included Check Spelling, for example. Our recent discussions, though, have focussed more on Find & Replace. I myself never use Check Spelling, so I'm happy. :-)

I'd like to take this opportunity to thank Philip (and the other Macro gurus here) for so generously sharing their expertise with the rest of us over the past year. I look forward to more discussions in 2020.

Cheers,
Adrian
MacBook Pro (M1 Pro, 2021)
macOS Ventura
Nisus Writer user since 1996
lellius
Posts: 54
Joined: 2002-08-15 22:06:44

Re: How to prevent text to be modified

Post by lellius »

Philip and Adrian,
Thanks for your combined useful solution.
I will try both the macros, until the desired command will be implemented in our application to block/unblock a selected text, and so to prevent inadvertent alteration (for instance with Find/Replace), and nevertheless t maintain the text still searchable.
A command to prevent check spelling on selected text already exists.
Cheers
lellius
Post Reply