How to adjust dired-omit-mode

[Origin]: https://emacs.stackexchange.com/questions/19558/how-to-adjust-dired-omit-mode

Goal:

  • When dired is opened by default hidden files should be hidden.
  • When the user clicks “M-q” hidden files must be shown except for “.” and “..”

I tried the following:

;don't show hidden files
(setq dired-omit-files "^\\..*$")
(defun swap-omit-files ()
  "Show/hide hidden files except . and .."
  (interactive)
  (if (string= dired-omit-files "^\\..*$")
      (setq dired-omit-files "^\\.\\.?$")
    (setq dired-omit-files "^\\..*$")
    )
  )

(add-hook 'dired-mode-hook
          (lambda ()
            (setq dired-omit-mode t)
            (define-key dired-mode-map (kbd "M-q") 'swap-omit-files)
            ))
Hidden file are indeed hidden by default, but something is wrong with swap-omit-files --- the hidden files are not shown.

How to fix?

shareimprove this question

 

This worked. We needed to revert-buffer after changing dired-omit-files:

(defun swap-omit-files ()
  "Show/hide hidden files except . and .."
  (interactive)
  (if (string= dired-omit-files "^\\..*$")
      (setq dired-omit-files "^\\.\\.?$")
    (setq dired-omit-files "^\\..*$")
    )
  (revert-buffer)
  )
shareimprove this answer
Advertisements

How do I byte-compile everything in my .emacs.d directory?

[Origin]: https://stackoverflow.com/questions/1217180/how-do-i-byte-compile-everything-in-my-emacs-d-directory

C-u 0 M-x byte-recompile-directory

will compile all the .el files in the directory and in all subdirectories below.

The C-u 0 part is to make it not ask about every .el file that does not have a .elc counterpart.

shareedit

Add change to a previous commit with Magit

[Origin]: https://emacs.stackexchange.com/questions/22557/add-change-to-a-previous-commit-with-magit

I have 2 commits, A then B, ready to be pushed. I realize I forgot to add something in A.

How can I add this change to A using Magit? I don’t even know which part of the Git documentation I should look at.

shareimprove this question

Let’s pretend for a moment that you want to add something to the HEAD commit, i.e. “the second commit B” in your example.

The commit popup on c features a binding “a Amend”. Pressing that key will “amend” the staged changes to the HEAD commit. Since commits are not mutable in Git, this will actually replace the old commit with a new commit. A buffer with the old commit message will pop up, so that you can modify it in case the added change also requires that you adjust the message. As always, press C-c C-c when you are done editing the message. This is equivalent to running git commit --amend on the command line.

  • a Amend — add the staged changes to HEAD and edit its commit message

Because it often happens that you only have to adjust the change or the message, Magit provides two additional variants:

  • e Extend — add the staged changes to HEAD without editing the commit message
  • w Reword— change the message of HEAD without adding the staged changes to it

When you want to edit a commit that isn’t HEAD, then the above won’t work. These commands always “modify” (i.e. replace) the HEAD commit. Git doesn’t provide a single command for modifying a commit other than HEAD so this is a bit more involved.

Magit does provide such a command, but because there are situations in which it is preferable to do this in multiple steps, we will discuss that first.

Modifying a commit other than HEAD can be broken down into three steps:

  1. Temporarily make that other commit (A) the HEAD.
  2. Modify the HEAD (as described above), resulting in commit A'.
  3. Tell Git to reapply the commits that followed A, but on top of A'.

This can be done using an interactive rebase. Type r to show the rebase popup. Then type mto invoke the “edit a commit” rebase variant. A buffer with recent commits appears. Move to the commit you want to modify and type C-c C-c to select it. Git then rewinds history to that commit and shows information about the ongoing rebase in the status buffer.

Modify HEAD as described above. Then tell Git that you are done by typing r r. If A' and Bconflict then rebase will stop at B and you have to resolve the conflict. After you have done so press r r to continue.

If you know that your changes to A will result in conflicts with B, then proceed as describe above, otherwise use the following approach.


Git allows creating “fixup commits” using git commit --fixup A. This creates a new commit, which records changes which “should have been made in another commit”. That commit becomes the new HEAD. There also exists a --squash variant. For information about the differences see the git-commit man page.

To actually combine the A commit and the new commit A' and then reapply B on top of that you have to use rebase. Magit provides a convenient command for doing so on r f.

The main difference to the above approach is that here we first create a new commit and then we rebase to combine that with the “target” and reapply B. Above we began with rebasing instead of committing.

In Magit both the --fixup and the --squash variants are available from the commit popup, on fand s. But Magit also provides “instant” variants of the fixup and squash commands on F and S. These variants create a new commit like the “non-instant” variants, but then they instantly combine the fixup commit with the target commit using rebase, without you having to invoke another command.

“Instant fixup” (c F) is essentially the same thing as “extend HEAD” (c e), except that it works for any commit, not just HEAD.


Further reading:

shareimprove this answer

After enabling ivy-mode, `dired-create-directory’ does not allow me to choose an entry not in the completion list

[origin]: https://emacs.stackexchange.com/questions/28982/after-enabling-ivy-mode-dired-create-directory-does-not-allow-me-to-choose-an/28983

Yes, obviously.

There are 2 cases. The name you want to create doesn’t match anything in the completion list, or when it does.

When it doesn’t, you can just do the totally obvious thing, type in the name and press enter.

If it does match, then pressing enter will get ivy to expand the name to the completion. Here you want to call ivy-immediate-done which is bound to C-M-j by default after you have typed the name.

shareimprove this answer

How do I force a favicon refresh

[Origin]: https://stackoverflow.com/questions/2208933/how-do-i-force-a-favicon-refresh

To refresh your site’s favicon you can force browsers to download a new version using the link tag and a querystring on your filename. This is especially helpful in production environments to make sure your users get the update.

<link rel="icon" href="http://www.yoursite.com/favicon.ico?v=2" />
shareedit

What does the construct x = x || y mean?

[Origin]: https://stackoverflow.com/questions/2802055/what-does-the-construct-x-x-y-mean/2802064

What is double pipe operator (||)?

Double pipe operator (||) is logical OR operator . In most languages it works the following way:

  • If the first value is false, it checks the second value. If it’s true, it returns true and if it’s false, it returns false.
  • If the first value is true, it always returns true, no matter what the second value is.

So it’s basically (note that it’s actually a pseudo-code, because you have to either give this function a name or wrap it in ( and ) to make it work):

function(x, y) {
  if (x) {
    return true;
  } else if (y) {
    return true;
  } else {
    return false;
  }
}

If you still don’t understand, look at this table:

      | true   false  
------+---------------
true  | true   true   
false | true   false  

In other words, it’s only false when both values are false.

How is it different in JavaScript?

JavaScript is a bit different, because it’s a loosely typed language. In this case it means that you can use || operator with values that are not booleans. Though it makes no sense, you can use this operator with for example a function and an object:

(function(){}) || {}

What happens there?

If values are not boolean, JavaScript makes implicit conversation to boolean. It means that if the value is falsey (e.g. 0""nullundefined (see also All falsey values in JavaScript)), it will be treated as false; otherwise it’s treated as true.

So the above example should give true, because empty function is truthy. Well, it doesn’t. It returns the empty function. That’s because JavaScript’s || operator doesn’t work as I wrote at the beginning. It works the following way:

  • If the first value is falsey, it returns the second value.
  • If the first value is truthy, it returns the first value.

Surprised? Actually, it’s “compatible” with the traditional || operator. It could be written as following function:

function(x, y) {
  if (x) {
    return x;
  } else {
    return y;
  }
}

If you pass a truthy value as x, it returns x, that is, a truthy value. So if you use it later in ifclause:

(function(x, y) {
  var eitherXorY = x || y;
  if (eitherXorY) {
    console.log("Either x or y is truthy.");
  } else {
    console.log("Neither x nor y is truthy");
  }
}(true/*, undefined*/))function(x, y) {
  if (x) {
    return x;
  } else {
    return y;
  }
}

you get "Either x or y is truthy.".

If x was falsey, eitherXorY would be y. In this case you would get the "Either x or y is truthy." if y was truthy; otherwise you’d get "Neither x nor y is truthy".

The actual question

Now, when you know how || operator works, you can probably make out by yourself what does x = x || y mean. If x is truthy, x is assigned to x, so actually nothing happens; otherwise y is assigned to x. It is commonly used to define default parameters to function, because default function parameters were introduces in ES6 and are not supported by older browsers. However, it is often considered as a bad programming practice, because it prevents you from passing a falsey value (which is not necessarily undefined or null) as a parameter. Consider following example:

function badFunction(/* boolean */flagA) {
  flagA = flagA || true;
  console.log("flagA is set to " + (flagA ? "true" : "false"));
}

It looks valid at the first sight. However, what would happen if you passed false as flagAparameter (since it’s boolean, i.e. can be true or false)? It would become true. In this example, there is no way to set flagA to false.

Better example would be to explicitly check whether the flagA is undefined, like that:

function goodFunction(/* boolean */flagA) {
  flagA = typeof flagA !== "undefined" ? flagA : true;
  console.log("flagA is set to " + (flagA ? "true" : "false"));
}

Though it’s longer, it always works and it’s easier to understand (which OP has proven by asking this question).

See also

shareedit

ASP.NET Core 1.0 on IIS error 502.5

[Origin]: https://stackoverflow.com/questions/38624453/asp-net-core-1-0-on-iis-error-502-5/43121152#43121152

I had this problem aswell (The error occurred both on VS 15 and 17). However on VS15 it returned a CONNECTION_REFUSED error and on VS17 it returned ASP.NET Core 1.0 on IIS error 502.5.

FIX

  1. Navigate to your project directory and locate the hidden folder .vs (it’s located in the projects folder dir). (Remember to show hidden files/folders)
  2. Close VS
  3. Delete .vs-folder
  4. Start VS as admin (.vs-folder will be recreated by VS)
shareedit