5

I want to have a command in Emacs to make it as opaque/transparent as I want (refer to the fabulous question that pointed out that transparency is possible in Emacs, and the EmacsWiki page linked there which has the code I am using below).

The EmacsWiki code sets "C-c t" to toggle the previously set transparency on and off:

;;(set-frame-parameter (selected-frame) 'alpha '(<active> [<inactive>]))  
(set-frame-parameter (selected-frame) 'alpha '(85 50))  
(add-to-list 'default-frame-alist '(alpha 85 50))

enter code here(eval-when-compile (require 'cl))  
(defun toggle-transparency ()  
(interactive)  
(if (/= 
    (cadr (find 'alpha (frame-parameters nil) :key #'car)) 
    100)  
   (set-frame-parameter nil 'alpha '(100 100))
 (set-frame-parameter nil 'alpha '(85 60))))  
 (global-set-key (kbd "C-c t") 'toggle-transparency)

What I would like to do is to be able to choose the % transparency when I am in Emacs.

If possible, I would like a command where I type for example "C-c t N" (where N is the % opaqueness) for the active frame, and then "M-c t N" for the inactive window.

If that can't be done like that, then maybe a command where if I type "C-c t" it asks me for the number which gives the opaqueness of the active window (and the same for the inactive window using "M-c t").

Thanks in advance for your time :)

Below are just some comments that are not important to answer the question if you are not interested:

I really want this because when I told my supervisor I was learning Emacs he said TexShop is much better and that I am using software from the 80's. I told him about the wonders of Emacs and he said TexShop has all of it and more. I matched everything he showed me except for the transparency (though he couldn't match the preview inside Emacs from preview-latex). I found the transparency thing by chance, and now I want to show him Emacs rules!

I imagine this will be a piece of cake for some of you, and even though I could get it done if I spent enough time trying to learn lisp or reading around, I am not a programmer and I have only been using Emacs and a mac for a week. I am lost already as it is! So thanks in advance for your time and help - I will learn lisp eventually!

Edit: My supervisor uses TextMate, not TeXShop. Does it make more sense now?

4
  • Your boss is wrong: Emacs is not from the 80's. Microsoft Windows, that's software from the 80's! Not that I have anything against software from the 80's (well, in general). ;) May 29, 2010 at 15:16
  • Ha, it is even older than that! Well, maybe that is why he likes his mac so much... Anyway, all features in TexShop are just "copied" from Emacs. They are just charging for something that already exists and is even better because lots of people contribute to (for?) it. Just give me a couple of months and when I am good enough with Emacs he will regret not using it! :P
    – Vivi
    May 29, 2010 at 15:34
  • sorry, I realised I gave the wrong name for the software. My supervisor uses TextMate, not TeXShop....
    – Vivi
    May 29, 2010 at 22:59
  • From the TextMate website (macromates.com): Created by a closet UNIX geek who was lured to the Mac platform by its ease of use and elegance, TextMate has been referred to as the culmination of Emacs and OS X and has resulted in countless requests for both a Windows and Linux port, but TextMate remains exclusive for the Mac, and that is how we like it!
    – Vivi
    May 29, 2010 at 23:23

1 Answer 1

6
(defun set-frame-alpha (arg &optional active)
  (interactive "nEnter alpha value (1-100): \np")
  (let* ((elt (assoc 'alpha default-frame-alist))
         (old (frame-parameter nil 'alpha))
         (new (cond ((atom old)     `(,arg ,arg))
                    ((eql 1 active) `(,arg ,(cadr old)))
                    (t              `(,(car old) ,arg)))))
    (if elt (setcdr elt new) (push `(alpha ,@new) default-frame-alist))
    (set-frame-parameter nil 'alpha new)))
(global-set-key (kbd "C-c t") 'set-frame-alpha)

Use C-c t for the active frame, and C-u C-c t for the non-active frame.

Edit:

One way to make the effect persists across sessions is to enable desktop-save-mode and add default-frame-alist to desktop-globals-to-save, through the customization interface: M-x customize-group RET desktop.

8
  • Sorry, I do have one question still... Can I just substitute the whole code above by this or do I need to leave part of that code in my .emacs file?
    – Vivi
    May 29, 2010 at 18:48
  • I tested it without anything else, then with the first three lines of the code I included in the question, then with the first four lines (the last three not counting the line which has ;;). In all those options, the problem is that whatever setting I make will disappear when I close Emacs and go back to either fully opaque (first option) or to 85 50 as defined. And I did save options, adopt frame parameters as default, but still, the setting is lost when I close the program. Is there a way to make the setting permanent or am I doing something wrong?
    – Vivi
    May 29, 2010 at 19:14
  • 1
    I hope I answered your question in the edit. Notice I also made some changes to the code.
    – huaiyuan
    May 29, 2010 at 19:47
  • I will try again and get back to you. I downloaded the lisp manual and was trying to figure out how to change the code, but I guess this isn't a half-an-hour thing....
    – Vivi
    May 29, 2010 at 20:01
  • OK, so I used the code you wrote and then selected the frame as default and saved options, using the menu options rather than what you wrote on the bottom, just because I am still not good with the shortcuts and I wanted to try with the menu click options in case it worked. Well, it did work! It is perfect now, thank you very much! I will use what you said in the edit. I am also happy that there were two codes so I can compare the two and start learning lisp. I am really grateful for your help, thank you :)
    – Vivi
    May 29, 2010 at 20:10

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.