text editors

classic Classic list List threaded Threaded
144 messages Options
1234 ... 8
Reply | Threaded
Open this post in threaded view
|

text editors

mick crane
Is there any text editor, preferably in a terminal that has the facility
to protect lines in the document, not the document itself ?
I've got 2 blocks of "code" that look similar and I keep editing the
wrong one and then it doesn't work.
mick

--
Key ID    4BFEBB31

Reply | Threaded
Open this post in threaded view
|

Re: text editors

Cindy Sue Causey
On 3/25/19, mick crane <[hidden email]> wrote:
> Is there any text editor, preferably in a terminal that has the facility
> to protect lines in the document, not the document itself ?
> I've got 2 blocks of "code" that look similar and I keep editing the
> wrong one and then it doesn't work.


I don't know of that, and I tried an "apt-cache search", too..

As I marked your thread "unread" to save in case something crosses my
path, it occurred to me that maybe you could at least find a way to do
something like colorize it?

Or in the meantime of finding something to lock that down, maybe you
could throw in one or more comments... that yell "Don't to do that!"
I've done that one... :)

Cindy :)
--
Cindy-Sue Causey
Talking Rock, Pickens County, Georgia, USA

* runs with birdseed *

Reply | Threaded
Open this post in threaded view
|

Re: text editors

Jude DaShiell-3
Even if it's not possible to colorize that block, hash marks could be
used on beginnings of lines to make those lines comments.  Then save the
document.  Then grep -v "^#" file >file2
That should remove your protected block from the saved file.  Now, edit
file2.  When finished, go into the original file and copy that block out
and paste it where you want it into file2.  Then overwrite the original
save file with file2.

On Mon, 25 Mar 2019, Cindy-Sue Causey wrote:

> Date: Mon, 25 Mar 2019 00:52:49
> From: Cindy-Sue Causey <[hidden email]>
> To: Debian Users <[hidden email]>
> Subject: Re: text editors
> Resent-Date: Mon, 25 Mar 2019 04:53:04 +0000 (UTC)
> Resent-From: [hidden email]
>
> On 3/25/19, mick crane <[hidden email]> wrote:
> > Is there any text editor, preferably in a terminal that has the facility
> > to protect lines in the document, not the document itself ?
> > I've got 2 blocks of "code" that look similar and I keep editing the
> > wrong one and then it doesn't work.
>
>
> I don't know of that, and I tried an "apt-cache search", too..
>
> As I marked your thread "unread" to save in case something crosses my
> path, it occurred to me that maybe you could at least find a way to do
> something like colorize it?
>
> Or in the meantime of finding something to lock that down, maybe you
> could throw in one or more comments... that yell "Don't to do that!"
> I've done that one... :)
>
> Cindy :)
>

--

Reply | Threaded
Open this post in threaded view
|

Re: text editors

Erik Christiansen
In reply to this post by mick crane
On 25.03.19 04:38, mick crane wrote:
> Is there any text editor, preferably in a terminal that has the facility to
> protect lines in the document, not the document itself ?
> I've got 2 blocks of "code" that look similar and I keep editing the wrong
> one and then it doesn't work.

The only thing I can think of, using vim (haven't used anything else for
30 years), is to turn on folding, and include a warning in a comment on
the first line of the block. Whether folding is on blank lines (simple
paragraph/block folding), or foldmethod=marker, the first line line is
displayed while folded.

Having to unfold the block, with only the warning and a short initial
line of code or block identifier visible, ought to be sufficiently
alerting if the blood level in the caffeine stream is not too high.

Putting the warning in "foldtext" wouldn't work, because then it'd
appear on all folded paragraphs - unless you used foldmethod=manual, and
only folded the troublesome blocks.

In extremis, you could write a vimscript function to do all sorts of
weird stuff on folding, but I think it would be a bit of work to put a
password on unfolding.

:help folding

Erik

Reply | Threaded
Open this post in threaded view
|

Re: text editors

Dan Hitt
In reply to this post by mick crane


On Sun, Mar 24, 2019 at 9:38 PM mick crane <[hidden email]> wrote:
Is there any text editor, preferably in a terminal that has the facility
to protect lines in the document, not the document itself ?
I've got 2 blocks of "code" that look similar and I keep editing the
wrong one and then it doesn't work.
mick


Hi Mick,

Actually, you can do this, at least in emacs, and this can be done in a terminal,
at least in an xterm.

If you're using emacs as an app, then it is just a matter of highlighting the region, then
choosing Edit > Text Properties > Special Properties > Read Only

(This is described in stack overflow, https://emacs.stackexchange.com/a/46066, where i
learned about it.)

However, you want to do it in a terminal, which is a good thing i think.

In this case, you probably have to access the menu things without a mouse.

But in xterm, at least, you can follow this procedure.

First, if you do not see the menu along the top, do M-x menu-bar-mode.  (If
you can see the menu, don't do M-x menu-bar-mode, because it toggles.)

Then, at least in xterm, you can do F10 (or function-F10) to get into the menus and
use the arrow keys to move around, and do the Edit > Text Properties thing.

Note that i do not know how to do this in xfce4-terminal, which is what debian
gives me, because F10 gets me into the xfce4-terminal.  But i don't know what
terminal you are using, so don't know if that's an issue for you or not.

Anyhow good luck, and it's a good question invho.

dan
Reply | Threaded
Open this post in threaded view
|

Re: text editors

john doe-6
In reply to this post by mick crane
On 3/25/2019 5:38 AM, mick crane wrote:
> Is there any text editor, preferably in a terminal that has the facility
> to protect lines in the document, not the document itself ?
> I've got 2 blocks of "code" that look similar and I keep editing the
> wrong one and then it doesn't work.

Not strictly an answer but I would track the good file for example in Git.
That way, you can always return back to a working state.

$ git checkout -- .

--
John Doe

Reply | Threaded
Open this post in threaded view
|

Re: text editors

mick crane
In reply to this post by Erik Christiansen
On 2019-03-25 05:29, Erik Christiansen wrote:

> On 25.03.19 04:38, mick crane wrote:
>> Is there any text editor, preferably in a terminal that has the
>> facility to
>> protect lines in the document, not the document itself ?
>> I've got 2 blocks of "code" that look similar and I keep editing the
>> wrong
>> one and then it doesn't work.
>
> The only thing I can think of, using vim (haven't used anything else
> for
> 30 years), is to turn on folding, and include a warning in a comment on
> the first line of the block. Whether folding is on blank lines (simple
> paragraph/block folding), or foldmethod=marker, the first line line is
> displayed while folded.
>
> Having to unfold the block, with only the warning and a short initial
> line of code or block identifier visible, ought to be sufficiently
> alerting if the blood level in the caffeine stream is not too high.
>
> Putting the warning in "foldtext" wouldn't work, because then it'd
> appear on all folded paragraphs - unless you used foldmethod=manual,
> and
> only folded the troublesome blocks.
>
> In extremis, you could write a vimscript function to do all sorts of
> weird stuff on folding, but I think it would be a bit of work to put a
> password on unfolding.
>
> :help folding
>
> Erik
not heard about folding.
I'm not very good at this.
kind of related I'm having difficulty copy and pasting.
If on windows [sorry] and in putty session for Debian no gui vi, if
highlight text with mouse then it is automatically saved to windows
clipboard for pasting but then in putty cannot scroll past bottom of
screen.
If set marks and then yank to other mark text is yanked but is not in
windows clipboard buffer for pasting.
In visual mode I can highlight all text with go to mark but that is not
in windows buffer either.
I tried all different commands to try to get text into windows buffer
but nothing seems to work.
mick
--
Key ID    4BFEBB31

Reply | Threaded
Open this post in threaded view
|

Re: text editors

Erik Christiansen
On 25.03.19 07:53, mick crane wrote:
> not heard about folding.

It can be very handy. I have around 420 pages of notes in one file. They
present as a one-page contents table with section page counts. While
cursoring down and then across opens a chosen fold, there are several
folding levels to the bottom. Hierarchical groping and digging is an
inefficient constraint suffered by GUIs; it is much quicker to just use
vim's '/' to search for a keyword. Given capitalised headings and
keywords, suffixed with a ':' for the major section on that topic, the
right line in 28532 lines is quickly found, and the required folds
opened automatically.

> I'm not very good at this.

Give it 30 years. Experience creeps up on you.

> kind of related I'm having difficulty copy and pasting.
> If on windows [sorry] and in putty session for Debian no gui vi, if

Commiserations. I'd be sorry too if I had to use windows. (Avoided it
entirely during 30 years in IT - took a fat redundancy package when
windows finally caught up, and retired.

> highlight text with mouse then it is automatically saved to windows
> clipboard for pasting but then in putty cannot scroll past bottom of screen.

Sounds like a putty limitation? I'll admit to only ever having copied to
an X11 clipboard, so can't offer relevant experience. I've never used
gvim - plain vim in an xterm works fine with the X11 clipboard, so long
as I remember to turn off autoindent before pasting, to avoid a
stairstep paste. (I have the F12 key mapped to toggle vim's "paste"
attribute, so a single key handles both on and off.)

> If set marks and then yank to other mark text is yanked but is not in
> windows clipboard buffer for pasting.

Have you checked whether the yank goes into the "* (clipboard) register?
Check also the "+ register, in case the windows clipboard is looking
there instead. A post on the vim-use ML might elicit more info related
to your environment. Back in 2011, Gary Johnson had a "Copy and paste
problem" which was fixed for windows with "set clipboard^=unnamed".)

    :help 'clipboard'
    :help :set^=

I tend to just use a mouse drag to grab text to the X11 clipboard for
pasting into something GUI.

> In visual mode I can highlight all text with go to mark but that is not in
> windows buffer either.
> I tried all different commands to try to get text into windows buffer but
> nothing seems to work.

Check   " :set clipboard ? "

IIUC, it should include unnamed and unnamedplus for problem-free
communication with the windows clipboard - inferring from a couple of
archive posts from 2011,12. Including unnamedplus isn't good for the
linux clipboard, though.

If all else fails, the vim-use mailing list is a darned sight more
knowledgeable on vim/windows stuff.

Erik

Reply | Threaded
Open this post in threaded view
|

Re: text editors

mick crane
On 2019-03-25 10:12, Erik Christiansen wrote:

> On 25.03.19 07:53, mick crane wrote:
>> not heard about folding.
>
> It can be very handy. I have around 420 pages of notes in one file.
> They
> present as a one-page contents table with section page counts. While
> cursoring down and then across opens a chosen fold, there are several
> folding levels to the bottom. Hierarchical groping and digging is an
> inefficient constraint suffered by GUIs; it is much quicker to just use
> vim's '/' to search for a keyword. Given capitalised headings and
> keywords, suffixed with a ':' for the major section on that topic, the
> right line in 28532 lines is quickly found, and the required folds
> opened automatically.
>
>> I'm not very good at this.
>
> Give it 30 years. Experience creeps up on you.
>
>> kind of related I'm having difficulty copy and pasting.
>> If on windows [sorry] and in putty session for Debian no gui vi, if
>
> Commiserations. I'd be sorry too if I had to use windows. (Avoided it
> entirely during 30 years in IT - took a fat redundancy package when
> windows finally caught up, and retired.
>
>> highlight text with mouse then it is automatically saved to windows
>> clipboard for pasting but then in putty cannot scroll past bottom of
>> screen.
>
> Sounds like a putty limitation? I'll admit to only ever having copied
> to
> an X11 clipboard, so can't offer relevant experience. I've never used
> gvim - plain vim in an xterm works fine with the X11 clipboard, so long
> as I remember to turn off autoindent before pasting, to avoid a
> stairstep paste. (I have the F12 key mapped to toggle vim's "paste"
> attribute, so a single key handles both on and off.)
>
>> If set marks and then yank to other mark text is yanked but is not in
>> windows clipboard buffer for pasting.
>
> Have you checked whether the yank goes into the "* (clipboard)
> register?
> Check also the "+ register, in case the windows clipboard is looking
> there instead. A post on the vim-use ML might elicit more info related
> to your environment. Back in 2011, Gary Johnson had a "Copy and paste
> problem" which was fixed for windows with "set clipboard^=unnamed".)
>
>     :help 'clipboard'
>     :help :set^=
>
> I tend to just use a mouse drag to grab text to the X11 clipboard for
> pasting into something GUI.
>
>> In visual mode I can highlight all text with go to mark but that is
>> not in
>> windows buffer either.
>> I tried all different commands to try to get text into windows buffer
>> but
>> nothing seems to work.
>
> Check   " :set clipboard ? "
>
> IIUC, it should include unnamed and unnamedplus for problem-free
> communication with the windows clipboard - inferring from a couple of
> archive posts from 2011,12. Including unnamedplus isn't good for the
> linux clipboard, though.
>
> If all else fails, the vim-use mailing list is a darned sight more
> knowledgeable on vim/windows stuff.
>
> Erik

tried "set clipboard=unnamed" and that.
":%y *" is supposed to copy to buffer and ":%y +" also says unrecognized
register or something"
": reg" shows
""
"0
":
"%
so I don't know.
obviously buffers are on different machines and maybe putty just buffers
what's on the screen.
Just wondered why it didn't work.

mick






--
Key ID    4BFEBB31

Reply | Threaded
Open this post in threaded view
|

Re: text editors

tomas@tuxteam.de
In reply to this post by mick crane
On Mon, Mar 25, 2019 at 04:38:31AM +0000, mick crane wrote:
> Is there any text editor, preferably in a terminal that has the
> facility to protect lines in the document, not the document itself ?
> I've got 2 blocks of "code" that look similar and I keep editing the
> wrong one and then it doesn't work.
> mick

What is "the document"? And what format is it in?

I have the strong suspicion that the answer to the first would be
"a configuration file of some sort" and to the second, it might
be "plain text".

In that case, I guess the straight answer to your question above
is "no".

And with the possibility that, perhaps, this (hypothetical) editor
won't be the only interface to your file, it might be wise to
consider another angle from which to attack the problem. A version
control system which allows you to easily revert to a previous
version of your file should anything go wrong. Or a post-commit
script charged of ensuring certain constraints before "activating"
your new version of the file (cf. visudo for inspiration). Just
two examples to perhaps get you started.

You can nevertheless get every civilised editor to do the trick
(vim, Emacs will easily comply) -- but perhaps you won't be
solving your problem...

Cheers
-- t

signature.asc (205 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: text editors

rhkramer
On Monday, March 25, 2019 07:05:14 AM [hidden email] wrote:

> On Mon, Mar 25, 2019 at 04:38:31AM +0000, mick crane wrote:
> > Is there any text editor, preferably in a terminal that has the
> > facility to protect lines in the document, not the document itself ?
> > I've got 2 blocks of "code" that look similar and I keep editing the
> > wrong one and then it doesn't work.
> > mick
>
> What is "the document"? And what format is it in?
>
> I have the strong suspicion that the answer to the first would be
> "a configuration file of some sort" and to the second, it might
> be "plain text".

Because there have been some interesting ideas in this thread, I'll add one
more (which might not be interesting). ;-)

I share the thought that the file / document might be  "a configuration file of
some sort" and have a suggestion that might be useful in that case, or if the
document is a program, and maybe even if it is just a text (not necessarily
plain) file that you open with a word processor.

The thought: put the part of the document that should not be modified in a read
only file, then "include" that file in another file that you allow to be edited
(read / write).

There are various ways to do this, depending on the computer language under
considereration (for example, #include in C / C++).  

There are equivalent approaches in bash, but I forget them (in bash, it might
be a little more convoluted, like an external / 3rd file that assembles a new
file from the read-only and read / write files.

I even have a vague recollection that there is / was an "include a file"
facility in (Microsoft) Word.  And, if so, because LIbre Office seems to make a
point of providing a feature complete "clone" (mcow) of Word, I suspect there
is an include facility there as well.

Reply | Threaded
Open this post in threaded view
|

Re: text editors

rhkramer
On Monday, March 25, 2019 07:47:31 AM [hidden email] wrote:
> I even have a vague recollection that there is / was an "include a file"
> facility in (Microsoft) Word.  And, if so, because LIbre Office seems to
> make a point of providing a feature complete "clone" (mcow) of Word, I
> suspect there is an include facility there as well.

Ahh, yes, after a little bit of googling, I found (and remember) that Word had
(and presumably still has) a master document concept -- which is essentially
the same as the include file concept.

Then, looking at ODF (Open Document Format), which is either the default or at
least one of the formats supported by Libre Office, also supports a master
document format.

Reply | Threaded
Open this post in threaded view
|

Re: text editors

Teemu Likonen-2
In reply to this post by mick crane
mick crane [2019-03-25 04:38:31Z] wrote:

> Is there any text editor, preferably in a terminal that has the facility
> to protect lines in the document, not the document itself ?
> I've got 2 blocks of "code" that look similar and I keep editing the
> wrong one and then it doesn't work.

GNU Emacs has text properties which can be added to any piece of text.
One of the properties is named "read-only". I made two functions to
handle the situation you described.

Put these function to you Emacs's init file (~/.emacs or
~/.emacs.d/init.el):


    (defun read-only-region (beg end)
      "Makes a region in the current buffer read only, from buffer
    position BEG to END. If this function is called interactively use
    the current hightlighted region."
      (interactive "r")
      (add-text-properties beg end '(read-only t)))

    (defun remove-read-only ()
      "Remove all read only text properties from the current buffer."
      (interactive)
      (let ((inhibit-read-only t))
        (remove-text-properties (point-min) (point-max)
                                '(read-only t))))


Select some text in a buffer and execute command "Alt+x
read-only-region". That area becomes read only. To remove all read only
text areas from the current buffer execute command "Alt+x
remove-read-only".

--
/// Teemu Likonen   - .-..   <https://keybase.io/tlikonen> //
// PGP: 4E10 55DC 84E9 DFF6 13D7 8557 719D 69D3 2453 9450 ///

signature.asc (497 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: text editors

Étienne Mollier
In reply to this post by rhkramer
On 3/25/19 12:47 PM, [hidden email] wrote:
> There are equivalent approaches in bash, but I forget them (in bash, it might
> be a little more convoluted, like an external / 3rd file that assembles a new
> file from the read-only and read / write files.

Good Day rhkramer,

Perhaps I missed some points, but wouldn't `.`, or `source`,
command do the trick, instead of building a script dynamically?

readonly.sh:
        # Don't touch that!
        PATH="/opt/thirparty/bin:$PATH"
        CPATH="/opt/thirparty/include:$CPATH"
        LD_LIBRARY_PATH="/opt/thirparty/lib:$LD_LIBRARY_PATH"
        export PATH CPATH LD_LIBRARY_PATH

main.sh:
        #! /bin/bash
        set -e
        # Loading environment from read only file
        . readonly.sh
        printf 'Using libraries in %s\n' "$LD_LIBRARY_PATH"
        do_stuff_with_thirdparty_program

If I need some configuration, or a sort of shell functions
library, this is something I would consider.

Kind Regards,
--
Étienne Mollier <[hidden email]>

All opinions are my own.


Reply | Threaded
Open this post in threaded view
|

Re: text editors

deloptes-2
Étienne Mollier wrote:

> If I need some configuration, or a sort of shell functions
> library, this is something I would consider.

+1

Reply | Threaded
Open this post in threaded view
|

Re: text editors

Ben Finney-3
In reply to this post by mick crane
mick crane <[hidden email]> writes:

> Is there any text editor, preferably in a terminal that has the
> facility to protect lines in the document, not the document itself ?

If by “protect” you mean “prevent editing these lines but not others”,
no I think that's not a feature of any editor I know.

You can achieve some protection by temporarily *hiding* lines you're not
wanting to edit.

Vim has “folding” (hiding a set of lines).

Emacs has “narrow&"9 to see nothing *but* a specific range of lines.

> I've got 2 blocks of "code" that look similar and I keep editing the
> wrong one and then it doesn't work.

I would use Emacs “narrow” commands for that; quickly narrow the focus
of the editor to only show me the area I'm meaning to edit, then easily
widen the range when I need to.

--
 \              “Ridicule is the only weapon which can be used against |
  `\       unintelligible propositions.” —Thomas Jefferson, 1816-07-30 |
_o__)                                                                  |
Ben Finney

Reply | Threaded
Open this post in threaded view
|

Re: text editors

Teemu Likonen-2
Ben Finney [2019-03-26 13:28:56+11] wrote:

> If by “protect” you mean “prevent editing these lines but not others”,
> no I think that's not a feature of any editor I know.

Emacs has that feature. See the "read-only" text property in the
following manual (info) page:

    (elisp) Special Properties

https://www.gnu.org/software/emacs/manual/html_node/elisp/Special-Properties.html#Special-Properties

In my other message in this thread I showed quick example functions for
(1) making a buffer area read only and (2) removing read only
properties. If someone wants to the functions could be made fancier, for
example with a button that removes the read only status.

--
/// Teemu Likonen   - .-..   <https://keybase.io/tlikonen> //
// PGP: 4E10 55DC 84E9 DFF6 13D7 8557 719D 69D3 2453 9450 ///

signature.asc (497 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: text editors

mick crane
In reply to this post by Teemu Likonen-2
On 2019-03-25 12:29, Teemu Likonen wrote:

> mick crane [2019-03-25 04:38:31Z] wrote:
>
>> Is there any text editor, preferably in a terminal that has the
>> facility
>> to protect lines in the document, not the document itself ?
>> I've got 2 blocks of "code" that look similar and I keep editing the
>> wrong one and then it doesn't work.
>
> GNU Emacs has text properties which can be added to any piece of text.
> One of the properties is named "read-only". I made two functions to
> handle the situation you described.
>
> Put these function to you Emacs's init file (~/.emacs or
> ~/.emacs.d/init.el):
>
>
>     (defun read-only-region (beg end)
>       "Makes a region in the current buffer read only, from buffer
>     position BEG to END. If this function is called interactively use
>     the current hightlighted region."
>       (interactive "r")
>       (add-text-properties beg end '(read-only t)))
>
>     (defun remove-read-only ()
>       "Remove all read only text properties from the current buffer."
>       (interactive)
>       (let ((inhibit-read-only t))
>         (remove-text-properties (point-min) (point-max)
>                                 '(read-only t))))
>
>
> Select some text in a buffer and execute command "Alt+x
> read-only-region". That area becomes read only. To remove all read only
> text areas from the current buffer execute command "Alt+x
> remove-read-only".

there it is then, although I've so far managed to avoid Emacs since
heard it is more of an operating system than an editor.

mick
--
Key ID    4BFEBB31

Reply | Threaded
Open this post in threaded view
|

Re: text editors

Teemu Likonen-2
mick crane [2019-03-26 07:35:11Z] wrote:

> there it is then, although I've so far managed to avoid Emacs since
> heard it is more of an operating system than an editor.

There are those who know Emacs, and there are those who know decades old
jokes about Emacs.

--
/// Teemu Likonen   - .-..   <https://keybase.io/tlikonen> //
// PGP: 4E10 55DC 84E9 DFF6 13D7 8557 719D 69D3 2453 9450 ///

signature.asc (497 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: text editors

John Hasler-3
mick crane wrote:
> there it is then, although I've so far managed to avoid Emacs since
> heard it is more of an operating system than an editor.

 Teemu Likonen writes:
> There are those who know Emacs, and there are those who know decades
> old jokes about Emacs.

And there are those who avoid learning what Emacs is actually like
because they have heard decades old jokes about it.
--
John Hasler
[hidden email]
Elmwood, WI USA

1234 ... 8