Change displayconfiguration with autolisp script - autolisp

I'm trying to call the displaymanager configuration selection, by an autolisp command, but it doesn't work.
When I call the command DISPLAYCONFIGSETCURRENT directly from the command line, it works! But in a autolisp script, it doesn't work and I can't figure it out..
My goal is, to call the DISPLAYCONFIGSETCURRENT and then preset my configuration, so it changes in one click or command.
Here is my code, and thanks in advance, every help is appreciated.
(defun c:changeConfig()
(setq config "Standard")
(command "DISPLAYCONFIGSETCURRENT" config)
(princ)
)

I found the solution my self :D
Here is my code:
(defun c:changeConfig()
(setq config "myDisplay")
(command "-AecDisplayConfigSetCurrent" config)
(princ)
)

Related

How do I control into which directory Emacs makes backup files dynamically?

I've seen the post How do I control how Emacs makes backup files? And a few similar post showing very similar solutions. I'm well aware of this approach. But it doesn't do quite what I would like it to do. I would like each file that I'm going to back up have its own personalized backup directory.
For example, let's say I have the following files in the current directory, /Users/me/project_a/
apple.txt
banana.txt
coconut.txt
when I edit these files, I would like them to have their backups stored in directories as follows:
/Users/me/project_a/.backups/apple.txt/
/Users/me/project_a/.backups/banana.txt/
/Users/me/project_a/.backups/coconut.txt/
If I another project directory, say /Users/me/project_b/, with files
needle.doc
thread.doc
thimble.doc
Then, their respective backups should be located as
/Users/me/project_b/.backups/needle.doc/
/Users/me/project_b/.backups/thread.doc/
/Users/me/project_b/.backups/thimble.doc/
Yes, I'm using the name of the file being backed up as part of the path name for the directory into which it's been saved. So, if I have three previous versions of thimble.doc, the full path name for the backups would be:
/Users/me/project_b/.backups/thimble.doc/thimble.doc.~1~
/Users/me/project_b/.backups/thimble.doc/thimble.doc.~2~
/Users/me/project_b/.backups/thimble.doc/thimble.doc.~3~
I have a work around to accomplish that (see below). Ideally, I would name the backups as:
/Users/me/project_b/.backups/thimble.doc/bak.~1~
/Users/me/project_b/.backups/thimble.doc/bak.~2~
/Users/me/project_b/.backups/thimble.doc/bak.~3~
I haven't yet figured out how to get there. (Any suggestions?)
Here's how I'm able to accomplish the less ideal version of this using the .dir-locals.el file with the following code for saving .txt and .tex files.
(let (a b)
(dolist (ae-fh (directory-files-recursively "." "\\.\\(txt\\|tex\\)$"))
(setq a (file-name-nondirectory ae-fh))
(setq a (replace-regexp-in-string "\\." "\\\\." a))
(setq b (concat "./.backups/" (file-name-nondirectory ae-fh)))
(add-to-list 'backup-directory-alist (cons a b))
))
I've already made backup-directory-alist a buffer-local variable.
This accomplishes what I want, but I don't really like this approach. I would like to altogether avoid using .dir-locals.el as a solution to this problem. But also, I would like to avoid junking up the backup-directory-alist. It would be nice if there were a hook I could apply to the backup process which would inform emacs on the fly how it should name the backup file.
Does anyone know how to do this or know where to point me? I've considered trying to redefine make-backup-file-name-function, but I don't entirely understand what I'm doing with the elisp and right now I've got projects that need to be worked on.
What can folks tell me?
I have a partial solution.
It avoids using .dir-locals.el as I want.
It somewhat creates the path on the fly as I want too.
It still uses backup-directory-alist
I add the following to my emacs init file:
(add-hook 'after-change-major-mode-hook
'(lambda ()
(let (a b)
(if (stringp (buffer-file-name))
(progn
(setq a (file-name-nondirectory (buffer-file-name)))
(setq a (replace-regexp-in-string "\\." "\\\\." a))
(setq b (concat "./.backups/" (file-name-nondirectory (buffer-file-name))))
(add-to-list 'backup-directory-alist (cons a b))
)
)
)))
I don't quite know enough about this hook. So, I'm not sure that this will always work. And, I should probably consider whether there might be files for which this convention really is undesirable.
The (stringp (buffer-file-name)) is minimally necessary in the case of buffers for which there is no underlying file: such as *scratch* or even the mini-buffers.
I am still interested in what solutions others might come up with. Ideally, the solution would be more like
/Users/me/project_b/.backups/thimble.doc/bak.~1~
/Users/me/project_b/.backups/thimble.doc/bak.~2~
/Users/me/project_b/.backups/thimble.doc/bak.~3~
than
/Users/me/project_b/.backups/thimble.doc/thimble.doc.~1~
/Users/me/project_b/.backups/thimble.doc/thimble.doc.~2~
/Users/me/project_b/.backups/thimble.doc/thimble.doc.~3~
UPDATE: Persistence will get you places!!!!
I finally did a google search on: "emacs how do i redefine make-backup-file-name". I found this description of an approach which I adapted to my situation. Namely, I did the following:
(defun z:backup:truncate.backup.name (file)
(concat (file-name-directory file) "bak"))
(advice-add 'make-backup-file-name-1 :filter-return #'z:backup:truncate.backup.name)
I'm not entirely sure of what everything is about.
I don't know what the #' syntax does.
I'm not sure what :filter-return does, though I can guess.
I should point out that I still need mae add-hook for 'after-change-major-mode-hook. Without it, I get errors. Apparently, I just can't write the advice function as
(defun z:backup:truncate.backup.name (file)
(concat (file-name-directory file) (file-name-nondirectory) "/bak"))
I tried it and got an error about not being able to back things up. And I think the reason for this is that backup-directory-alist is used to determine the directory path. I've got some ideas for some tweaks here. But this is where things stand currently.
UPDATE: no more need for my add-hook to after-change-major-mode-hook
I've gotten rid of the issue with the backup directory alist not necessarily being set for the correct directory. This is my final form for z:backup:truncate.backup.name
(defun z:backup:truncate.backup.name ()
(let* (
(dir (file-name-directory (buffer-file-name)))
(fh (file-name-nondirectory (buffer-file-name)))
(qdir (concat dir ".backups/" fh))
)
(if (not (file-directory-p qdir))
(progn
(if (file-directory-p dir)
(progn
(make-directory qdir)
))))
(concat qdir "/bak")))
So now more having to tweak backup-directory-alist. I've accomplished everything I wanted. YEAH.

How can i make the spacemacs compilation buffer split horizontally?

I am setting (setq split-width-threshold 100) in my dotspacemacs/user-config, in order to make various buffers split horizontally when the window is wide enough. This works as intended for magit status etc.
However, the compilation log buffer seems to disregard this, and always opens on the bottom.
How can i make the compilation buffer adhere to the split-width-threshold? Alternatively, how can get it to always split horizontally?
I am quite new to both emacs and spacemacs.
The reason for the compilation not to obey your settings is because spacemacs comes with purpose-mode enabled by default. If you use that, then it is a matter of modifying the purpose layouts as you wish. However if you are not using the purpose-mode, then disabling it fixes the issue for me. To just try it out you can do SPC SPC purpose-mode RET and then (with only one window opened) run the compilation.
Here's one way to do it (SPC f e d to get to your config file, then you could put this in the existing dotspacemacs-user-config function) -- here I've shown how to get both grep and compilation buffers popping up on the right:
(require 'dash)
(defun my/popwin-on-right (alist-item)
(let ((props-alist (seq-partition (cdr alist-item) 2)))
(setf (alist-get :position props-alist) '(right))
(setf (alist-get :height props-alist) '(1.0))
(setf (alist-get :width props-alist) '(0.5))
(let ((flattened (apply #'append props-alist)))
(cons (car alist-item) flattened))))
(custom-set-variables
'(popwin:special-display-config
(--map-when (-contains? '("*compilation*" "*grep*") (car it))
(my/popwin-on-right it)
popwin:special-display-config)))
or you could just set popwin:special-display-config more directly, replacing the --map-when call there with a literal list. Just view the variable's existing value e.g. using SPC SPC ielm <RET> to get nice formatting, then cut and paste it in (you'll need to quote the list using '). Or you could do what I do when I want to set a customizable variable as a literal value: use SPC SPC customize, let that update the end of your spacemacs config file with its blob of generated code, then copy out the custom-set-variables it generates into your dotspacemacs-user-config, and delete the blob of code that customize generated).
From another answer
(setq split-height-threshold nil)
(setq split-width-threshold 0)
If you want these settings to only affect compile
(defadvice compile (around split-horizontally activate)
(let ((split-width-threshold 0)
(split-height-threshold nil))
ad-do-it))

Unable to batch process through command-line

(Under Windows 7 x64)
I originally tried to use BIMP to apply a cutout effect to a folder but FU-cutout is one of the few that doesn't appear in the plug-in's list. I read somewhere that was because I hadn't install GIMP while customizing to allow compatibility with older plug-in and I de/reinstalled to try and fix this to no avail. So I decided to use script-fu instead but find myself unable to make it work out through the command line.
I have checked on a few sites explaining how to batch script (including the official GIMP doc) and ended with the follow code.
(define (hmd-batch-stylize pattern colours smoothness)
(let* ( (filelist (cadr (file-glob pattern 1) ) )
)
(while (not (null? filelist))
(let* ((filename (car filelist))
(image (car (gimp-file-load RUN-NONINTERACTIVE
filename filename)))
(drawable (car (gimp-image-get-active-layer image)))
)
(gimp-brightness-contrast drawable 35 40)
(FU-cutout RUN-NONINTERACTIVE
image drawable colours smoothness TRUE)
(gimp-file-save RUN-NONINTERACTIVE
image drawable filename filename)
(gimp-image-delete image)
)
(set! filelist (cdr filelist))
)
))
(I also register the script but for the sake of simplicity I won't add this code here). Then I open the command line and write
gimp -i -b '(hmd-batch-stylize "C:\Users\User\Desktop\3\*jpg" 32 1)' -b '(gimp-quit 0)'
in the gimp directory (I tried the directory where my files are but gimp isn't recognized as a command there). The gimp console starts up, fails to execute a bunch of dlls and a folder (all part of GMIC) with the mention "Exec format error", then I get two "Batch command completed successfully" at which point the command line freezes until I close it.
I searched online for days hoping to find a solution but no one seems to have the same problem as I do so no solution has worked yet. Help would be greatly appreciated.
PS: I thought of instead creating a script that would appear in BIMP and act as a middle-man to access the FU-cutout but I can't find how to pass the current image/filename being used by BIMP as an argument. If anyone knows how, I feel that might be my simplest way of working around this problem.

elisp: generate LaTeX PDF document

I trying to completely automatize sending job applications. First step, to put the name of the company in a letter. It almost works, but it is stuck because it asks what command to use. Reading the documentation, I thought it could be disabled by a prefix argument, but I got something wrong. Also, it doesn't need to flash by visually, it could be done completely as a background process. I'll paste the code and you'll understand immediately:
(Oh, I'm using LaTeX/P mode in emacs - the goal is to not only update the .tex but also the .pdf file)
(defun edit-letter (comp-name)
(let ((path "~/work/letter/comp"))
(edit-letter-file-path comp-name (concat path "/eng/letter.tex"))
(edit-letter-file-path comp-name (concat path "/swe/brev.tex")) ))
(defun edit-letter-file-path (company-name file-path)
(find-file file-path)
(goto-line 14)
(kill-line)
(insert (format "\\textbf{To %s}\n" company-name))
(setq current-prefix-arg nil)
(call-interactively 'TeX-command-master) ; asks what command
(kill-buffer) ) ; doesn't work
(edit-letter "Digital Power Now")
It's not entirely clear from your question what you're after, but if you want to use AucTeX to call a LaTeX/PDFTex/BibTex process without getting prompted for the command name, you can use this:
(TeX-command "LaTeX" 'TeX-master-file)
Try this in place of (call-interactively 'TeX-command-master) above. When you're using LaTeX/P "LaTeX" really means pdflatex.

Can't rebind key C-z in xemacs

For some reason, "C-z" is mapped to suspend-or-iconify-emacs and I can't seem to get it to rebind to something less annoying. (I like using ctrl-z for undo, but doing nothing would at least be better than suspending every time I accidentally hit the key)
I've tried doing it interactively:
M-x global-set-key, then Set key C-z to command: undo.
M-x describe-key-briefly gives me C-z runs the command suspend-or-iconify-emacs
I've tried going to the scratch buffer and evaluating:
(global-set-key (kbd "C-z") 'undo) and (global-set-key "\C-z" 'undo), and it is of course in my .xemacs/init.el file.
Nothing seems to actually rebind the key.
This is happening on XEmacs 21.5, in Fundamental mode. Any ideas on how to troubleshoot this?
edit: Ok here is a hack that gets around the problem by redefining the suspend function to undo:
(defun suspend-or-iconify-emacs () (interactive) (undo))
I can't actually suspend emacs anymore, but that's actually ok with me.
Try evaluating this:
(define-key global-window-system-map [(control z)] 'undo)
(assuming that you aren't running XEmacs in tty-mode, but I guess you are not, if you want to iconify :-))
I used C-h b to find out what *-map to modify.
I have the following code in my .emacs:
(global-set-key (kbd "C-z") 'eshell)
It will start an eshell, and it works.
The C-z combination is pretty standard on Unix/Linux, if you're working in a terminal with e.g. vi, lynx or mutt and presses C-z the program will suspend and you will be back in the shell. Issuing the 'fg' command will pop the program back again. As Emacs has its own shell, I like spawning that when pressing C-z in Emacs.
You can also add the following hook, that will remap C-z in the eshell. That way pressing C-z in the eshell with get you back to the buffer you were editing.
(add-hook 'eshell-mode-hook
(lambda ()
(local-set-key (kbd "C-z") 'bury-buffer)))
Put that at the end of your .xemacs/init.el :
(global-set-key (kbd "C-z") 'undo)
Or maybe you have a misconfigured keyboard or operating system.
Do C-h k C-z to see if xemacs really receives a C-z key.
I had the same problem with C-f. I wanted it to map to isearch-forward, but instead it kept moving one character forward.
I finally solved my problem by adding
(global-unset-key [?\C-f])
(global-set-key [?\C-f] 'isearch-forward)
Apparently the issue is that C-f (and C-z) is a "real" key, that is, it's something that a terminal recognizes (it's ASCII 0x06, 0x1a for C-z), so you need the "?\" in front of "C-f".
This is the only thing I got to work.
HTH
(EDIT: I should note that I use emacs, not xemacs)