Session manager for emacs (with high ssh usage) - ssh

I'm interested in using a session manager in emacs with the possibility of saving sessions by name.
The problem is that I almost exclusively use emacs to edit remote files. For this, I use tramp, which also works perfectly.
I want to have my sessions saved, including remote files and term buffers.
Does anyone know of a good way of saving sessions? I don't really care about windows sizes or splits
I have tried the following, which does not work:
Followed the instructions in this post, and tried out desktop.el. Searching and saving by name works perfectly.
Like this post recommends, I added this line so tramps are saved too:
(setq desktop-buffers-not-to-save "^$")
But, as I said, this does not work.

Ok, now it works. I'll post what I did, but I don't really know which was the problem.
Apparently, the line
(setq desktop-buffers-not-to-save "^$")
was not working. So I enter the customization interactively (M-x customize-gruop RET desktop RET, changed the value of Desktop Buffers Not To Save to none, reload .emacs, and it worked.

Related

Make PhpStorm watch (specific) file and upload upon change

I'm looking for a way for PhpStorm to watch a file - so that every time it changes, it should sync that file to the remote server. And the 'Upload external changes'-option (with the 'On explicit save action') is not working for me. It's close - but no cigar. It makes me save the css-file twice - and only after the second time I save the scss-file, then it uploads the gulp-compiled-style.css-file, as I would like it to do after the first 'save'. I know it's an itty-bitty thing - but for something that I easily do 200-400 times per day, I would like it to run as smooth as possible. It's both the time I spend saving the file twice - but it's also the doubt in my mind, every time something doesn't act like I want it to - then I always have to check first, if the file is uploaded properly.
I'm working with Wordpress and I have a 5-8 SCSS-files, that are being compiled using gulp. The gulp-procedures are quite comprehensive (autoprefixer, merge-media-queries, minifycss, etc., etc.), so it takes a couple of miliseconds for the file to be compiled. I assume that it's that compile-time that makes PhpStorm 'miss' that the style.css has changed - and therefore don't upload it on the first 'save'. Because sometimes everything is uploaded after the first 'save' - but it's only every 8th time (or so).
Extra fun fact (that may indicate where the body is burried): If i run the gulp watch from a terminal in the background, then I have to save the file, wait for at least 2-4 seconds and then save again, before the gulp-compiled-style.css-file is uploaded. If I press 'save', 'save', 'save', 'save' - with less than those 2-4 seconds pause, but with only 1 seconds pause, then PhpStorm never sync's the gulp-compiled-style.css-file.
If I run the gulp watch from PhpStorm's Gulp-integration (not the terminal, but the Gulp-prompt), then I can save twice in a row with only .5 second pause between (as soon as the progress bar in the bottom disappears) - and then it uploads (every time, - consistently).
It's only the upload of the gulp-compiled-style.css-file that is the problem. Everything else is working perfectly.
Here's what I have tried:
**Attempt1) I've previously used Atom, where the FTP-configuration was established using a plugin with a .ftpconfig-file. In that file, there was a 'watch: []'-parameter, where I could specify a file to 'watch'. That worked wonders!! I've tried finding a plugin that did something of the sort - but couldn't find it.
**Attempt2) I read one of the support-pages, concerning the same. It seems like that if the SCSS-files are compiled using PhpStorm, then it knows to upload the style.css-file (after it has been compiled). I can't setup my gulp-file using PhpStorms' SCSS-compilation (since it compiles it and then pipes the content through multiple procedures. And if I change projects and have to set that up every time, then that would be a pain to maintain.
**Attempt3) I thought about making a macro or something. And then seeing if I could remap CMD-s to 'save-current-file-and-execute-the-macro'. But then if I don't edit the scss-file (but just some php-file), then it would still upload the style.css-file. It's by no means a pretty solution, - but it just shows how far out in the ropes I've been, to find a solution to automate this.
**Attempt4) I thought about building it into the gulp-file, that it has to upload the style.css-file after compiling the style.css-file. I thought about getting the host and the username from the .idea-folder - and getting the password from the keychain and then establishing the sftp-connection that way. But it quickly became extensive to do this, so I hoped that there was an easier/better way.
Addition1
LazyOne asked, what I had tried with the File Watchers, so here goes. I tried making PhpStorm compile the Scss-file (so PhpStorm basically did what Gulp does for me today).
So that was a SCSS-filewatcher (file type), the scope was the SCSS-files in my project, pointed the 'Program' to my ruby-installed scss-file, etc., etc., etc.
However... I realized that it was difficult to get PhpStorm to do the same thing to the Scss-files as the Gulp-file does.
The Gulp-file that I'm using is supplied with each project (as a default) - and we're several webdesigners working on the same projects. So if I suddenly do something other that use that Gulp-file, then I'm pretty sure that I will have to be able to produce the exact same result, - otherwise I'm pretty sure that my colleagues will skin me alive. But I made it as far as to have this as my Arguments, before I gave up (I still need to do several things in this line, before it does what my Gulp-file does):
--no-cache --update $FileName$:../../style.css --style compressed --sourcemap=none
... However... When doing that, then I could conclude that the style.css-file was uploaded on every save (score!). Which means that if I can just setup some kind of File Watcher, then hopefully PhpStorm will watch that file and therefore upload it after Gulp has compiled the style.css.
So I tried to make a File Watcher, that watches the style.css-file - but I didn't know what to put as my 'Program'. Since basically I want PhpStorm to poke the style.css-file three times with a stick - and thereafter realize that the file has changed and upload it to the server. Is that possible to do automatically?
Ok. Here's how it's done!
The important part is that PhpStorm watches the style.css-file. It will do that, if you point a File Watcher to look at the file. Now, at first I tried running the Gulp-file with a File Watcher. Then I tried compiling the scss-files with the File Watcher. But that is not necessary. The important part is the 'Output paths to refresh' (as #LazyOne pointed out in the comments). So the best solution I've come to, is to make a bash-script that does nothing. It looks like this:
#!/bin/bash
sleep .01
I've called that 'donothing'. I don't have to do the sleep .01 for it to work, - but it doesn't stop it from working (based on the 20 upload tests I've done). And in my mind, it's better if there's a short delay, after the scss-files are saved (so the gulp-integration in PhpStorm have time to finish compiling the style.css-file).
Here's the setup of my File Watcher:
The scope is a custom-made one, and I've set it to this:
file[PROJECTNAME]:wp-content/themes/THEME_NAME/assets/sass/*
But I assume the scope could just be the entire project, since it's just looking for when SCSS-files change in that scope, before the 'Program' is executed (if I've understood this whole File Watcher thingy properly).
And I'm working on a project, where the SCSS-files are at
/wp-content/themes/THEME_NAME/assets/sass/STYLEDIRNAME/
And in this case, then the 'Output paths to refresh' should be set to something along these lines:
$FileDirRelativeToProjectRoot$/../../style.css
or
$ProjectFileDir$/wp-content/themes/THEME_NAME/style.css
And if you unfold 'Other options', then you have to set Working directory to be the root of the project, for it to work:
/Users/USERNAME/dropbox/foo/bar/
A downfall for this solution is, if PhpStorm are faster than the Gulp-task, - since it would then upload the style.css-file before the Gulp-task has finished compiling it (and therefore uploading the old or an incomplete file). That didn't happen during my 20 brief tests. But if it happens, then I would set a higher delay in the 'donothing'-file and see if that solves it.
Addition 1
I just experienced, that it wasn't working - that it didn't upload style.css upon every compilation/save (but I could swear that the setup was correct). So I restarted PhpStorm and then it worked. I tried restarting the gulp watch-process first, - but that didn't make a difference.
Another, much simpler solution is to set the File Watchers scope for SCSS files to "All Changed Files".
This is what my File Watcher setup looks like.
It compiles the .scss file, copies the minified .css into another folder, and then automatically uploads both files to the server if you have "Auto upload" enabled.
(You might note that I'm not using the SCSS compiler but the PHP-based PSCSS, which is about 70% faster and can be installed via composer global require scssphp/scssphp).

Process.Start does not always work

I created a protocol generation tool that reads some data from a websource, allows the user to filter some of the fields an generate a protocol based on given filterdata. The protocol is generated as a word document that is edited multiple times, on multiple layers, before shown to the user.
For some users the line:
Process.Start(pathtowordfile)
does not open Word, for others it works fine.
Even more strange: if the useres try to generate the protocol the first time it opens. if they change one of the filters and generate again, the file does not open. But it is generated correctly, you are able to open it manually.
We are using Windows 7 on all machines and, in general, the User has no administrativ privileges on the machine.
Are there any alternatives to
Process.Start()
?
Not sure how the code can sometimes work, but the critical bit I think would be to make sure you set UseShellExecute=true when you are trying to Process.Start a file that is not an executable.
https://msdn.microsoft.com/en-us/library/system.diagnostics.processstartinfo.useshellexecute%28v=vs.110%29.aspx
I haven't looked into it in quite awhile, but last I checked shell execute relies on the Word application to be properly registered with DDE so Windows knows what to do with a .doc(x) file. Word may not be installed "properly".
after trying varios things, including Wonko's hint, I dicided to use the interop.Word.Wordapplication to display the document. It doesn't explain why process.start not does the job but anyway, now everybody of the users is happy^^

Mercurial does not show modified file

I've been working with Mercurial (on windows and using TortoiseHg) for some time now, but today I experienced something I just do not understand.
I'm sure, that I've made some modifications to a file (view.xaml). When I manually compare the local file with the one committed to the repository, I can identify the modifications. But when I do a hg status it does not show any modified files...
First thing I checked was, that I had actually saved my work. While doing this, I noticed, that in the windows explorer, it showed the file as modified for just a short time (like 10-20 seconds). Then it changed again and showed as unmodified.
Second thing I checked was the ignore list and view.xaml is not on the ignore list.
Can anyone enlighten me, as to why Mercurial does not show this file as modified?

Access vi history

I just accidentally pasted a $200 SSL certificate in the private key file and saved in vi. The private key is now lost. I know I yanked the existing data before replacing it and saving. Is it possible to retrieve this data somehow? I think no, but I figured I'd ask.
If you haven't quit vi, you can just 'p'.. no?
If your vi session is still running, and you haven't written your file yet, just do [esc]:q! and you should be back to your original file.
Or just hit p to paste the stuff you yanked previously.
You might have an id.rsa~ file hanging around. If so, that is your backup file.
It sounds like you've already written your file, so you are probably out of luck. Can you generate a new keypair and ask your cert vendor to re-issue the cert?
In the future, you might want to look into setting the backup option in vim. This used to be a default setting in Linux distributions back in the day, but it definitely isn't the default on my mac now.
If you yanked the data before you overwrote it, it probably should still be accessible using registers (:help registers):
:registers
will show you the contents of all registers.
If you find the lost text, it can be yanked by using the number displayed at the beginning of the line, e.g. by issuing "3p in normal mode.
UPDATE: The question was about vi, not vim, right? Then the command registers might not exist; I think the yank registers 0-9 are a vim extension.
I don't suppose you have backups set do you (doc)? If not, can't you do u?

Force a Samba process to close a file

Is there a way to force a Samba process to close a given file without killing it?
Samba opens a process for each client connection, and sometimes I see it holds open files far longer than needed. Usually i just kill the process, and the (windows) client will reopen it the next time it access the share; but sometimes it's actively reading other file for a long time, and i'd like to just 'kill' one file, and not the whole connection.
edit: I've tried the 'net rpc file close ', but doesn't seem to work. Anybody knows why?
edit: this is the best mention i've found of something similar. It seems to be a problem on the win32 client, something that microsoft servers have a workaround for; but Samba doesn't. I wish the net rpc file close <fileid> command worked, I'll keep trying to find out why. I'm accepting LuckyLindy's answer, even if it didn't solve the problem, because it's the only useful procedure in this case.
This happens all the time on our systems, particularly when connecting to Samba from a Win98 machine. We follow these steps to solve it (which are probably similar to yours):
See which computer is using the file (i.e. lsof|grep -i <file_name>)
Try to open that file from the offending computer, or see if a process is hiding in task manager that we can close
If no luck, have the user exit any important network programs
Kill the user's Samba process from linux (i.e. kill -9 <pid>)
I wish there was a better way!
I am creating a new answer, since my first answer really just contained more questions, and really was not a whole lot of help.
After doing a bit of searching, I have not been able to find any current open bugs for the latest version of Samba, please check out the Samba Bug Report website, and create a new bug. This is the simplest way to get someone to suggest ideas as to how to possibly fix it, and have developers look at the issue. LuckyLindy left a comment in my previous answer saying that this is the way it has been for 5 years now, well the project is Open Source the best way to fix something that is wrong by reporting it, and or providing patches.
I have also found one mailing list entry: Samba Open files, they suggest adding posix locking=no to the configuration file, as long as you don't also have the files handed out over NFS not locking the file should be okay, that is if the file is being held is locked.
If you wanted too, you could write a program that uses ptrace and attaches to the program, and it goes through and unlocks and closes all the files. However, be aware that this might possibly leave Samba in an unknown state, which can be more dangerous.
The work around that I have already mentioned is to periodically restart samba as a work around. I know it is not a solution but it might work temporarily.
This is probably answered here: How to close a file descriptor from another process in unix systems
At a guess, 'net rpc file close' probably doesn't work because the interprocess communication telling Samba to close the file winds up not being looked at until the file you want to close is done being read.
If there isn't an explicit option in samba, that would be impossible to externally close an open file descriptor with standard unix interfaces.
Generally speaking, you can't meddle with a process file descriptors from the outside. Yet as root you can of course do that as you seen in that phrack article from 1997: http://www.phrack.org/issues.html?issue=51&id=5#article - I wouldn't recommend doing that on a production system though...
The better question in this case would be why? Why do you want to close a file early? What purpose does it ultimately have to close the file? What are you attempting to accomplish?
Samba provides commands for viewing open files and closing them.
To list all open files:
net rpc file -U ADadmin%password
Replace ADadmin and password with the credentials of a Windows AD domain admin. This gives you a file id, username of who's got it open, lock status, and the filename. You'll frequently want to filter the results by piping them through grep.
Once you've found a file you want to close, copy its file id number and use this command:
net rpc file close fileid -U ADadmin%password
I needed to accomplish something like this, so that I could easily unmount devices I happened to be sharing. I wrote this quick bash script:
#!/bin/bash
PIDS_TO_CLOSE=$(smbstatus -L | tail -n-3 | grep "$1" | cut -d' ' -f1 - | sort -u | sed '/^$/$
for PID in $PIDS_TO_CLOSE; do
kill $PID
done
It takes a single argument, the paths to close:
smbclose /media/drive
Any path that matches that argument (by grep) is closed, so you should be pretty specific with it. (Only files open through samba are affected.) Obviously, you need root to close files opened by other users, but it works fine for files you have open. Note that as with any other force closing of a file, data corruption can occur. As long as the files are inactive, it should be fine though.
It's pretty ugly, but for my use-case (closing whole mount points) it works well enough.