SlackwareThis Forum is for the discussion of Slackware Linux.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I'm using Kate for editing multiple files. Currently, I'm working with a Python script. I have some blank lines between some sections of code in a declared class. If there is not an indentation between the sections, the interactive session breaks up the sections as if they're separate pieces of code. I've tried using spaces and tabs but with either, when I save the file, the indentation disappears and I have to recreate the indentation again. I used Tools > Indentation > Python and > Normal and neither saves the indentations. What do I need to change to make Kate save the indentations?
Code:
class data(torch.utils.data.Dataset):
def __init__(self, root, transforms=None, target_transform=None):
self.root = root
self.transforms = transforms
self.target_transform = target_transform
# load all image files, sorting them to
# ensure that they are aligned
self.imgs = list(sorted(os.listdir(os.path.join(root,"image"))))
self.masks = list(sorted(os.listdir(os.path.join(root,"mask"))))
##This line needs to have an indentation saved to it.
def __getitem__(self, idx):
# load images ad masks
img_path = os.path.join(self.root, "images", self.imgs[idx])
Have you confirmed, by using an editor such as vi/vim that the indents are in fact missing ? And if you use another editor and edit afterwards with Kate, do they change again ?
I made the indents while the file was open in Kate. I saved the file, and the cursor sitting in one of the indents immediately dropped back to the left margin of the editor. I opened the file in Vi and ran the cursor to the two places where there should be indents and the cursor moves to the next line when I use the arrow key to move into what "should" be an indent. I created an indent while in Vi in a couple of places and saved the file and then opened again in Kate. The indents made while the file was open in Vi remained in Kate. But I still can't make an indent and save it in Kate. Does the same thing: on an unindented line, make an indent and save. The cursor instantly drops back to margin like there is no indent.
It's a long shot, in fact a very long shot, but try starting Kate from the command line, creating and saving a test file, closing that tab (but not exiting Kate), then reopening the file. I'm hoping you might get some useful messages to the terminal.
As an aside, I was unable to duplicate this issue with Kate v. 20.12.0 on Mageia v. 8. I had created indentations with both tabs and spaces and they were present when I reopened the file.
Just a comment: there can be issues caused by automatic language detection and formatting, also by auto-indent settings and similar (like tab <=> space replacement).
Additionally (especially for python) we have black, flake8 and other tools to format the code.
~/Documents$ kate
Qt: Session management error: networkIdsList argument is NULL
kf.kio.core: The recently-used.xbel is not an XBEL file, overwriting.
kf.kio.core: The recently-used.xbel is not an XBEL file, overwriting.
kf.kio.core: The recently-used.xbel is not an XBEL file, overwriting.
kf.kio.core: The recently-used.xbel is not an XBEL file, overwriting.
kf.kio.core: The recently-used.xbel is not an XBEL file, overwriting.
kf.kio.core: The recently-used.xbel is not an XBEL file, overwriting.
Those are all the messages from the console while I tried your suggestion.
I created a file, typed a few characters on a line, used tab and space with no characters on following lines, and typed characters with trailing spaces on another lines. It looked like for a moment it was going to save the spaces and indents, but when I opened the files ("all" and .py) back up in the same Kate session, they were not saved. I opened the files in Vi and there were no spaces there as well. I'm using Kate 21.12.3.
There's a setting in kate that automatically removes spaces on empty lines when you save a file.
Settings -> Configure Kate... -> Open/Save -> General -> Automatic Cleanups on Save -> Remove trailing spaces
This is also a setting that can be controlled from editorconfig files. So if you work on a project using those, what's defined in them overrides whatever is configured in kate.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.